If LevelFieldName is empty don't log level (#313)
This commit is contained in:
parent
0f923d7926
commit
19c98f6d3e
2
log.go
2
log.go
|
@ -424,7 +424,7 @@ func (l *Logger) newEvent(level Level, done func(string)) *Event {
|
|||
e := newEvent(l.w, level)
|
||||
e.done = done
|
||||
e.ch = l.hooks
|
||||
if level != NoLevel {
|
||||
if level != NoLevel && LevelFieldName != "" {
|
||||
e.Str(LevelFieldName, LevelFieldMarshalFunc(level))
|
||||
}
|
||||
if l.context != nil && len(l.context) > 1 {
|
||||
|
|
18
log_test.go
18
log_test.go
|
@ -77,6 +77,24 @@ func TestInfo(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestEmptyLevelFieldName(t *testing.T) {
|
||||
fieldName := LevelFieldName
|
||||
LevelFieldName = ""
|
||||
|
||||
t.Run("empty setting", func(t *testing.T) {
|
||||
out := &bytes.Buffer{}
|
||||
log := New(out)
|
||||
log.Info().
|
||||
Str("foo", "bar").
|
||||
Int("n", 123).
|
||||
Msg("")
|
||||
if got, want := decodeIfBinaryToString(out.Bytes()), `{"foo":"bar","n":123}`+"\n"; got != want {
|
||||
t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
|
||||
}
|
||||
})
|
||||
LevelFieldName = fieldName
|
||||
}
|
||||
|
||||
func TestWith(t *testing.T) {
|
||||
out := &bytes.Buffer{}
|
||||
ctx := New(out).With().
|
||||
|
|
Loading…
Reference in New Issue