[log] allow for custom color funcs
This commit is contained in:
parent
8f5a175ff4
commit
a5fcc94a3b
|
@ -3,6 +3,8 @@ package log
|
|||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kit/kit/log/term"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -29,3 +31,19 @@ func TestingLogger() Logger {
|
|||
|
||||
return _testingLogger
|
||||
}
|
||||
|
||||
// TestingLoggerWithColorFn allow you to provide your own color function. See
|
||||
// TestingLogger for documentation.
|
||||
func TestingLoggerWithColorFn(colorFn func(keyvals ...interface{}) term.FgBgColor) Logger {
|
||||
if _testingLogger != nil {
|
||||
return _testingLogger
|
||||
}
|
||||
|
||||
if testing.Verbose() {
|
||||
_testingLogger = NewTMLoggerWithColorFn(NewSyncWriter(os.Stdout), colorFn)
|
||||
} else {
|
||||
_testingLogger = NewNopLogger()
|
||||
}
|
||||
|
||||
return _testingLogger
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ func NewTMLogger(w io.Writer) Logger {
|
|||
return &tmLogger{term.NewLogger(w, NewTMFmtLogger, colorFn)}
|
||||
}
|
||||
|
||||
// NewTMLoggerWithColorFn allow you to provide your own color function. See
|
||||
// NewTMLogger for documentation.
|
||||
func NewTMLoggerWithColorFn(w io.Writer, colorFn func(keyvals ...interface{}) term.FgBgColor) Logger {
|
||||
return &tmLogger{term.NewLogger(w, NewTMFmtLogger, colorFn)}
|
||||
}
|
||||
|
||||
// Info logs a message at level Info.
|
||||
func (l *tmLogger) Info(msg string, keyvals ...interface{}) error {
|
||||
lWithLevel := kitlevel.Info(l.srcLogger)
|
||||
|
|
Loading…
Reference in New Issue