diff --git a/level.go b/level.go index 591e1a08a..614648ab4 100644 --- a/level.go +++ b/level.go @@ -98,6 +98,11 @@ func (lvl AtomicLevel) SetLevel(l zapcore.Level) { lvl.l.Store(int32(l)) } +// String returns the string representation of the underlying Level. +func (lvl AtomicLevel) String() string { + return lvl.Level().String() +} + // UnmarshalText unmarshals the text to an AtomicLevel. It uses the same text // representations as the static zapcore.Levels ("debug", "info", "warn", // "error", "dpanic", "panic", and "fatal"). diff --git a/level_test.go b/level_test.go index fd8827d6e..a8fb650c3 100644 --- a/level_test.go +++ b/level_test.go @@ -111,6 +111,7 @@ func TestAtomicLevelText(t *testing.T) { marshaled, err := lvl.MarshalText() assert.NoError(t, err, `Unexpected error marshalling level "%v" to text.`, tt.expect) assert.Equal(t, tt.text, string(marshaled), "Expected marshaled text to match") + assert.Equal(t, tt.text, lvl.String(), "Expected Stringer call to match") } } }