flog/type.go
2018-05-08 17:39:09 +02:00

46 lines
945 B
Go

package flog
import (
"io"
"time"
)
// LevelType defines the level type
type LevelType uint8
// All possible log levels
const (
LevelDebug LevelType = iota
LevelInfo
LevelWarning
LevelError
LevelCritical
)
var levels = []string{`debug`, `info`, `warning`, `error`, `critical`}
// String returns the name of the level as string
func (l LevelType) String() string {
return levels[l]
}
// LogEntry is an entry for the log
type LogEntry struct {
Level LevelType `json:"level"`
Time time.Time `json:"time"`
Message string `json:"message"`
StackTrace []StackTraceEntry `json:"stack_trace,omitempty"`
}
// StackTraceEntry is an entry in the stack trace
type StackTraceEntry struct {
Function string `json:"function"`
File string `json:"file"`
Line int `json:"line"`
}
// LogFormatType defines the log format
type LogFormatType interface {
FormatMessage(io.Writer, LogEntry)
}