Adding a new interface instead of updating FieldLogger

This commit is contained in:
Dongming Bi 2020-11-20 13:48:18 -08:00
parent 6abeffb8b1
commit 2d76c42baf
No known key found for this signature in database
GPG Key ID: AE7B02B3C7564435
2 changed files with 15 additions and 2 deletions

View File

@ -168,8 +168,6 @@ type FieldLogger interface {
Fatalln(args ...interface{}) Fatalln(args ...interface{})
Panicln(args ...interface{}) Panicln(args ...interface{})
SetLevel(level Level)
IsLevelEnabled(level Level) bool
// IsDebugEnabled() bool // IsDebugEnabled() bool
// IsInfoEnabled() bool // IsInfoEnabled() bool
// IsWarnEnabled() bool // IsWarnEnabled() bool
@ -178,6 +176,12 @@ type FieldLogger interface {
// IsPanicEnabled() bool // IsPanicEnabled() bool
} }
type Ext2FieldLogger interface {
FieldLogger
SetLevel(level Level)
IsLevelEnabled(level Level) bool
}
// Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is // Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is
// here for consistancy. Do not use. Use Logger or Entry instead. // here for consistancy. Do not use. Use Logger or Entry instead.
type Ext1FieldLogger interface { type Ext1FieldLogger interface {

View File

@ -631,14 +631,23 @@ func TestLogrusInterfaces(t *testing.T) {
b := l.WithField("key", "value") b := l.WithField("key", "value")
b.Debug("Test") b.Debug("Test")
} }
fn2 := func(xl Ext2FieldLogger) {
var l FieldLogger = xl
b := l.WithField("key", "value")
b.Debug("Test")
}
// test logger // test logger
logger := New() logger := New()
logger.Out = &buffer logger.Out = &buffer
fn(logger) fn(logger)
fn2(logger)
// test Entry // test Entry
e := logger.WithField("another", "value") e := logger.WithField("another", "value")
fn(e) fn(e)
fn2(e)
} }
// Implements io.Writer using channels for synchronization, so we can wait on // Implements io.Writer using channels for synchronization, so we can wait on