Skip to content

Commit

Permalink
Merge pull request sirupsen#320 from little-arhat/feature-logrus-inte…
Browse files Browse the repository at this point in the history
…rface

Add LogrusLogger interface for Entry and Logger
  • Loading branch information
sirupsen committed Mar 17, 2016
2 parents e110284 + 1196d67 commit bb78923
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
36 changes: 36 additions & 0 deletions logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,39 @@ type StdLogger interface {
Panicf(string, ...interface{})
Panicln(...interface{})
}

// Logrus logger interface generalizes Entry and Logger types, so you can take any of these
type LogrusLogger interface {
// we can return LogrusLogger here, but this will require many changes and will
// possible break backward compatiblity
WithField(key string, value interface{}) *Entry
WithFields(fields Fields) *Entry
WithError(err error) *Entry

Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Printf(format string, args ...interface{})
Warnf(format string, args ...interface{})
Warningf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})

Debug(args ...interface{})
Info(args ...interface{})
Print(args ...interface{})
Warn(args ...interface{})
Warning(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Panic(args ...interface{})

Debugln(args ...interface{})
Infoln(args ...interface{})
Println(args ...interface{})
Warnln(args ...interface{})
Warningln(args ...interface{})
Errorln(args ...interface{})
Fatalln(args ...interface{})
Panicln(args ...interface{})
}
17 changes: 17 additions & 0 deletions logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,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)
}

0 comments on commit bb78923

Please sign in to comment.