Add LogrusLogger interface for Entry and Logger
This make it possible for client code to accept either Logger or Entry. For example, utility function may accept logger object to inform fatal errors and it is job of the calling code to provide either generic top-level logger, or request-bound Entry created using .WithFields. (fixes #308)
This commit is contained in:
@@ -314,3 +314,20 @@ func TestLoggingRace(t *testing.T) {
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// Compile test
|
||||
func TestLogrusInterface(t *testing.T) {
|
||||
var buffer bytes.Buffer
|
||||
fn := func(l LogrusLogger) {
|
||||
b := l.WithField("key", "value")
|
||||
b.Debug("Test")
|
||||
}
|
||||
// test logger
|
||||
logger := New()
|
||||
logger.Out = &buffer
|
||||
fn(logger)
|
||||
|
||||
// test Entry
|
||||
e := logger.WithField("another", "value")
|
||||
fn(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user