From 2d76c42baf3ba98e9871ab1df874b20fabbaf4ff Mon Sep 17 00:00:00 2001 From: Dongming Bi Date: Fri, 20 Nov 2020 13:48:18 -0800 Subject: [PATCH] Adding a new interface instead of updating FieldLogger --- logrus.go | 8 ++++++-- logrus_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/logrus.go b/logrus.go index 75f25a1..8731d2b 100644 --- a/logrus.go +++ b/logrus.go @@ -168,8 +168,6 @@ type FieldLogger interface { Fatalln(args ...interface{}) Panicln(args ...interface{}) - SetLevel(level Level) - IsLevelEnabled(level Level) bool // IsDebugEnabled() bool // IsInfoEnabled() bool // IsWarnEnabled() bool @@ -178,6 +176,12 @@ type FieldLogger interface { // IsPanicEnabled() bool } +type Ext2FieldLogger interface { + FieldLogger + SetLevel(level Level) + IsLevelEnabled(level Level) bool +} + // Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is // here for consistancy. Do not use. Use Logger or Entry instead. type Ext1FieldLogger interface { diff --git a/logrus_test.go b/logrus_test.go index 9c3c920..46ef867 100644 --- a/logrus_test.go +++ b/logrus_test.go @@ -631,14 +631,23 @@ func TestLogrusInterfaces(t *testing.T) { b := l.WithField("key", "value") b.Debug("Test") } + + fn2 := func(xl Ext2FieldLogger) { + var l FieldLogger = xl + b := l.WithField("key", "value") + b.Debug("Test") + } + // test logger logger := New() logger.Out = &buffer fn(logger) + fn2(logger) // test Entry e := logger.WithField("another", "value") fn(e) + fn2(e) } // Implements io.Writer using channels for synchronization, so we can wait on