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