From 97e1bef2cc0484018fd74e2bdf12fe6d410fb25b Mon Sep 17 00:00:00 2001 From: Antoine Grondin Date: Fri, 14 Mar 2014 14:50:08 -0400 Subject: [PATCH 1/2] Fix logger.StdLogger to really be a plugin stdlib/log.Logger. --- logrus.go | 2 +- logrus_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/logrus.go b/logrus.go index 9fa2c99..2fe14b1 100644 --- a/logrus.go +++ b/logrus.go @@ -33,7 +33,7 @@ const ( type StandardLogger interface { Print(...interface{}) Printf(string, ...interface{}) - Printfln(...interface{}) + Println(...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) diff --git a/logrus_test.go b/logrus_test.go index 64baa40..e94fd3b 100644 --- a/logrus_test.go +++ b/logrus_test.go @@ -33,6 +33,24 @@ func TestPrint(t *testing.T) { }) } +func TestPrintf(t *testing.T) { + LogAndAssertJSON(t, func(log *Logger) { + log.Printf("%s", "test") + }, func(fields Fields) { + assert.Equal(t, fields["msg"], "test") + assert.Equal(t, fields["level"], "info") + }) +} + +func TestPrintln(t *testing.T) { + LogAndAssertJSON(t, func(log *Logger) { + log.Println("test") + }, func(fields Fields) { + assert.Equal(t, fields["msg"], "test") + assert.Equal(t, fields["level"], "info") + }) +} + func TestInfo(t *testing.T) { LogAndAssertJSON(t, func(log *Logger) { log.Info("test") From bf45b308e940cc2a593721b8fed8bef9cfb400c3 Mon Sep 17 00:00:00 2001 From: Antoine Grondin Date: Fri, 14 Mar 2014 15:07:57 -0400 Subject: [PATCH 2/2] Rename StandartLogger. Clean way to assert log.Logger realizes logrus interface. --- logrus.go | 11 +++++++++-- logrus_test.go | 18 ------------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/logrus.go b/logrus.go index 2fe14b1..2376db3 100644 --- a/logrus.go +++ b/logrus.go @@ -1,5 +1,9 @@ package logrus +import ( + "log" +) + // Fields type, used to pass to `WithFields`. type Fields map[string]interface{} @@ -27,10 +31,13 @@ const ( Debug ) -// StandardLogger is what your logrus-enabled library should take, that way +// Won't compile if StdLogger can't be realized by a log.Logger +var _ StdLogger = &log.Logger{} + +// StdLogger is what your logrus-enabled library should take, that way // it'll accept a stdlib logger and a logrus logger. There's no standard // interface, this is the closest we get, unfortunately. -type StandardLogger interface { +type StdLogger interface { Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) diff --git a/logrus_test.go b/logrus_test.go index e94fd3b..64baa40 100644 --- a/logrus_test.go +++ b/logrus_test.go @@ -33,24 +33,6 @@ func TestPrint(t *testing.T) { }) } -func TestPrintf(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Printf("%s", "test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - assert.Equal(t, fields["level"], "info") - }) -} - -func TestPrintln(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Println("test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - assert.Equal(t, fields["level"], "info") - }) -} - func TestInfo(t *testing.T) { LogAndAssertJSON(t, func(log *Logger) { log.Info("test")