mirror of https://github.com/sirupsen/logrus.git
Rename StandartLogger. Clean way to assert log.Logger realizes logrus
interface.
This commit is contained in:
parent
97e1bef2cc
commit
bf45b308e9
11
logrus.go
11
logrus.go
|
@ -1,5 +1,9 @@
|
||||||
package logrus
|
package logrus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
// Fields type, used to pass to `WithFields`.
|
// Fields type, used to pass to `WithFields`.
|
||||||
type Fields map[string]interface{}
|
type Fields map[string]interface{}
|
||||||
|
|
||||||
|
@ -27,10 +31,13 @@ const (
|
||||||
Debug
|
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
|
// it'll accept a stdlib logger and a logrus logger. There's no standard
|
||||||
// interface, this is the closest we get, unfortunately.
|
// interface, this is the closest we get, unfortunately.
|
||||||
type StandardLogger interface {
|
type StdLogger interface {
|
||||||
Print(...interface{})
|
Print(...interface{})
|
||||||
Printf(string, ...interface{})
|
Printf(string, ...interface{})
|
||||||
Println(...interface{})
|
Println(...interface{})
|
||||||
|
|
|
@ -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) {
|
func TestInfo(t *testing.T) {
|
||||||
LogAndAssertJSON(t, func(log *Logger) {
|
LogAndAssertJSON(t, func(log *Logger) {
|
||||||
log.Info("test")
|
log.Info("test")
|
||||||
|
|
Loading…
Reference in New Issue