Browse Source

correct impl of WithLevel

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

+ 22
- 0
log/logger.go View File

@ -4,6 +4,7 @@ import (
"fmt"
kitlog "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
)
// Logger is what any Tendermint library should take.
@ -25,3 +26,24 @@ func With(logger Logger, keyvals ...interface{}) Logger {
panic(fmt.Sprintf("Unexpected logger of type %T", logger))
}
}
// WithLevel returns a copy of the logger with a level set to lvl.
func WithLevel(logger Logger, lvl string) Logger {
switch logger.(type) {
case *tmLogger:
switch lvl {
case "info":
return &tmLogger{level.NewFilter(logger.(*tmLogger).srcLogger, level.AllowInfo())}
case "debug":
return &tmLogger{level.NewFilter(logger.(*tmLogger).srcLogger, level.AllowDebug())}
case "error":
return &tmLogger{level.NewFilter(logger.(*tmLogger).srcLogger, level.AllowError())}
default:
panic(fmt.Sprintf("Unexpected level %v, expect either \"info\" or \"debug\" or \"error\"", lvl))
}
case *nopLogger:
return logger
default:
panic(fmt.Sprintf("Unexpected logger of type %T", logger))
}
}

+ 0
- 14
log/tm_logger.go View File

@ -41,20 +41,6 @@ func NewTMLogger(w io.Writer) Logger {
return &tmLogger{srcLogger}
}
// WithLevel returns a copy of the logger with a level set to lvl.
func (l *tmLogger) WithLevel(lvl string) Logger {
switch lvl {
case "info":
return &tmLogger{level.NewFilter(l.srcLogger, level.AllowInfo())}
case "debug":
return &tmLogger{level.NewFilter(l.srcLogger, level.AllowDebug())}
case "error":
return &tmLogger{level.NewFilter(l.srcLogger, level.AllowError())}
default:
panic(fmt.Sprintf("Unexpected level %v, expect either \"info\" or \"debug\" or \"error\"", lvl))
}
}
// Info logs a message at level Info.
func (l *tmLogger) Info(msg string, keyvals ...interface{}) error {
lWithLevel := level.Info(l.srcLogger)


Loading…
Cancel
Save