Add ability to customize level values

This commit is contained in:
Olivier Poitrey 2021-05-14 00:05:00 +02:00
parent 4de2fcc128
commit 3c3b4a354e
2 changed files with 23 additions and 8 deletions

View File

@ -27,7 +27,22 @@ var (
// LevelFieldName is the field name used for the level field. // LevelFieldName is the field name used for the level field.
LevelFieldName = "level" LevelFieldName = "level"
// LevelFieldMarshalFunc allows customization of global level field marshaling // LevelTraceValue is the value used for the trace level field.
LevelTraceValue = "trace"
// LevelDebugValue is the value used for the debug level field.
LevelDebugValue = "debug"
// LevelInfoValue is the value used for the info level field.
LevelInfoValue = "info"
// LevelWarnValue is the value used for the warn level field.
LevelWarnValue = "warn"
// LevelErrorValue is the value used for the error level field.
LevelErrorValue = "error"
// LevelFatalValue is the value used for the fatal level field.
LevelFatalValue = "fatal"
// LevelPanicValue is the value used for the panic level field.
LevelPanicValue = "panic"
// LevelFieldMarshalFunc allows customization of global level field marshaling.
LevelFieldMarshalFunc = func(l Level) string { LevelFieldMarshalFunc = func(l Level) string {
return l.String() return l.String()
} }

14
log.go
View File

@ -134,19 +134,19 @@ const (
func (l Level) String() string { func (l Level) String() string {
switch l { switch l {
case TraceLevel: case TraceLevel:
return "trace" return LevelTraceValue
case DebugLevel: case DebugLevel:
return "debug" return LevelDebugValue
case InfoLevel: case InfoLevel:
return "info" return LevelInfoValue
case WarnLevel: case WarnLevel:
return "warn" return LevelWarnValue
case ErrorLevel: case ErrorLevel:
return "error" return LevelErrorValue
case FatalLevel: case FatalLevel:
return "fatal" return LevelFatalValue
case PanicLevel: case PanicLevel:
return "panic" return LevelPanicValue
case Disabled: case Disabled:
return "disabled" return "disabled"
case NoLevel: case NoLevel: