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:
Roma Sokolov
2016-02-01 16:55:14 +00:00
parent 433488c23f
commit 1196d67b47
2 changed files with 53 additions and 0 deletions
+17
View File
@@ -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)
}