Add loggers that take functions as input

This commit is contained in:
Ariel Simulevski
2020-04-10 12:42:19 +02:00
parent d417be0fe6
commit 7d248fa1b1
4 changed files with 125 additions and 0 deletions
+26
View File
@@ -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",
}
})
}