|
|
@ -14,8 +14,6 @@ var _ Logger = (*defaultLogger)(nil) |
|
|
|
|
|
|
|
type defaultLogger struct { |
|
|
|
zerolog.Logger |
|
|
|
|
|
|
|
trace bool |
|
|
|
} |
|
|
|
|
|
|
|
// NewDefaultLogger returns a default logger that can be used within Tendermint
|
|
|
@ -26,7 +24,7 @@ type defaultLogger struct { |
|
|
|
// Since zerolog supports typed structured logging and it is difficult to reflect
|
|
|
|
// that in a generic interface, all logging methods accept a series of key/value
|
|
|
|
// pair tuples, where the key must be a string.
|
|
|
|
func NewDefaultLogger(format, level string, trace bool) (Logger, error) { |
|
|
|
func NewDefaultLogger(format, level string) (Logger, error) { |
|
|
|
var logWriter io.Writer |
|
|
|
switch strings.ToLower(format) { |
|
|
|
case LogFormatPlain, LogFormatText: |
|
|
@ -59,14 +57,13 @@ func NewDefaultLogger(format, level string, trace bool) (Logger, error) { |
|
|
|
|
|
|
|
return defaultLogger{ |
|
|
|
Logger: zerolog.New(logWriter).Level(logLevel).With().Timestamp().Logger(), |
|
|
|
trace: trace, |
|
|
|
}, nil |
|
|
|
} |
|
|
|
|
|
|
|
// MustNewDefaultLogger delegates a call NewDefaultLogger where it panics on
|
|
|
|
// error.
|
|
|
|
func MustNewDefaultLogger(format, level string, trace bool) Logger { |
|
|
|
logger, err := NewDefaultLogger(format, level, trace) |
|
|
|
func MustNewDefaultLogger(format, level string) Logger { |
|
|
|
logger, err := NewDefaultLogger(format, level) |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
} |
|
|
@ -80,9 +77,6 @@ func (l defaultLogger) Info(msg string, keyVals ...interface{}) { |
|
|
|
|
|
|
|
func (l defaultLogger) Error(msg string, keyVals ...interface{}) { |
|
|
|
e := l.Logger.Error() |
|
|
|
if l.trace { |
|
|
|
e = e.Stack() |
|
|
|
} |
|
|
|
|
|
|
|
e.Fields(getLogFields(keyVals...)).Msg(msg) |
|
|
|
} |
|
|
@ -94,7 +88,6 @@ func (l defaultLogger) Debug(msg string, keyVals ...interface{}) { |
|
|
|
func (l defaultLogger) With(keyVals ...interface{}) Logger { |
|
|
|
return defaultLogger{ |
|
|
|
Logger: l.Logger.With().Fields(getLogFields(keyVals...)).Logger(), |
|
|
|
trace: l.trace, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|