Add loggers that take functions as input
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package logrus_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLogger_LogFn(t *testing.T) {
|
||||
log.SetFormatter(&log.JSONFormatter{})
|
||||
log.SetLevel(log.WarnLevel)
|
||||
|
||||
log.InfoFn(func() []interface{} {
|
||||
fmt.Println("This is never run")
|
||||
return []interface{} {
|
||||
"Hello",
|
||||
}
|
||||
})
|
||||
|
||||
log.ErrorFn(func() []interface{} {
|
||||
fmt.Println("This runs")
|
||||
return []interface{} {
|
||||
"Oopsi",
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user