79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package simplelog
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Event struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Level string `json:"level"`
|
|
Message string `json:"message"`
|
|
Data json.RawMessage `json:"data"`
|
|
}
|
|
|
|
type ExtendedEvent interface {
|
|
GetID() uuid.UUID
|
|
GetTimestamp() time.Time
|
|
GetLevel() string
|
|
GetMessage() string
|
|
GetData() json.RawMessage
|
|
GetFile() string
|
|
GetLine() int
|
|
}
|
|
|
|
type extendedEvent struct {
|
|
Event
|
|
File string `json:"file"`
|
|
Line int `json:"line"`
|
|
}
|
|
|
|
func (e extendedEvent) GetID() uuid.UUID {
|
|
return e.ID
|
|
}
|
|
|
|
func (e extendedEvent) GetTimestamp() time.Time {
|
|
return e.Timestamp
|
|
}
|
|
|
|
func (e extendedEvent) GetLevel() string {
|
|
return e.Level
|
|
}
|
|
|
|
func (e extendedEvent) GetMessage() string {
|
|
return e.Message
|
|
}
|
|
|
|
func (e extendedEvent) GetData() json.RawMessage {
|
|
return e.Data
|
|
}
|
|
|
|
func (e extendedEvent) GetFile() string {
|
|
return e.File
|
|
}
|
|
|
|
func (e extendedEvent) GetLine() int {
|
|
return e.Line
|
|
}
|
|
|
|
func NewExtendedEvent(level, message string, data json.RawMessage, file string, line int) ExtendedEvent {
|
|
return extendedEvent{
|
|
Event: NewEvent(level, message, data),
|
|
File: file,
|
|
Line: line,
|
|
}
|
|
}
|
|
|
|
func NewEvent(level, message string, data json.RawMessage) Event {
|
|
return Event{
|
|
ID: uuid.New(),
|
|
Timestamp: time.Now().UTC(),
|
|
Level: level,
|
|
Message: message,
|
|
Data: data,
|
|
}
|
|
}
|