[log] allow for custom color funcs

This commit is contained in:
Anton Kaliaev 2017-05-14 12:03:45 +02:00
parent 8f5a175ff4
commit a5fcc94a3b
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
2 changed files with 24 additions and 0 deletions

View File

@ -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
}

View File

@ -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)