|
|
@ -1,10 +1,9 @@ |
|
|
|
package log |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
|
|
|
|
kitlog "github.com/go-kit/kit/log" |
|
|
|
"github.com/go-kit/kit/log/level" |
|
|
|
) |
|
|
|
|
|
|
|
// Logger is what any Tendermint library should take.
|
|
|
@ -12,38 +11,21 @@ type Logger interface { |
|
|
|
Debug(msg string, keyvals ...interface{}) error |
|
|
|
Info(msg string, keyvals ...interface{}) error |
|
|
|
Error(msg string, keyvals ...interface{}) error |
|
|
|
} |
|
|
|
|
|
|
|
// With returns a new contextual logger with keyvals prepended to those passed
|
|
|
|
// to calls to Info, Debug or Error.
|
|
|
|
func With(logger Logger, keyvals ...interface{}) Logger { |
|
|
|
switch logger.(type) { |
|
|
|
case *tmLogger: |
|
|
|
return &tmLogger{kitlog.With(logger.(*tmLogger).srcLogger, keyvals...)} |
|
|
|
case *nopLogger: |
|
|
|
return logger |
|
|
|
default: |
|
|
|
panic(fmt.Sprintf("Unexpected logger of type %T", logger)) |
|
|
|
} |
|
|
|
With(keyvals ...interface{}) Logger |
|
|
|
WithLevel(lvl string) 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)) |
|
|
|
} |
|
|
|
// NewSyncWriter returns a new writer that is safe for concurrent use by
|
|
|
|
// multiple goroutines. Writes to the returned writer are passed on to w. If
|
|
|
|
// another write is already in progress, the calling goroutine blocks until
|
|
|
|
// the writer is available.
|
|
|
|
//
|
|
|
|
// If w implements the following interface, so does the returned writer.
|
|
|
|
//
|
|
|
|
// interface {
|
|
|
|
// Fd() uintptr
|
|
|
|
// }
|
|
|
|
func NewSyncWriter(w io.Writer) io.Writer { |
|
|
|
return kitlog.NewSyncWriter(w) |
|
|
|
} |