Browse Source

[log] allow for custom color funcs

pull/1842/head
Anton Kaliaev 8 years ago
parent
commit
a5fcc94a3b
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 24 additions and 0 deletions
  1. +18
    -0
      log/testing_logger.go
  2. +6
    -0
      log/tm_logger.go

+ 18
- 0
log/testing_logger.go 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
}

+ 6
- 0
log/tm_logger.go 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)


Loading…
Cancel
Save