Skip to content

Commit

Permalink
Add ability to customize level values
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed May 13, 2021
1 parent 4de2fcc commit 3c3b4a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 16 additions & 1 deletion globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ var (
// LevelFieldName is the field name used for the level field.
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 {
return l.String()
}
Expand Down
14 changes: 7 additions & 7 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ const (
func (l Level) String() string {
switch l {
case TraceLevel:
return "trace"
return LevelTraceValue
case DebugLevel:
return "debug"
return LevelDebugValue
case InfoLevel:
return "info"
return LevelInfoValue
case WarnLevel:
return "warn"
return LevelWarnValue
case ErrorLevel:
return "error"
return LevelErrorValue
case FatalLevel:
return "fatal"
return LevelFatalValue
case PanicLevel:
return "panic"
return LevelPanicValue
case Disabled:
return "disabled"
case NoLevel:
Expand Down

0 comments on commit 3c3b4a3

Please sign in to comment.