The current StructuredLogger interface is too basic and requires manually filtering some data, especially the levels
Suggestion:
Drop "ts" from the key-value pair (is provided by used logger anyways)
Drop "level" from
Add "Debug", "Info", "Warn", "Error" functions to (maybe to a separate, more specific Logger interface)
These functions should as first parameter take the actual log message, afterwards a "key-value" of structured information, like the current interface
this allows us to more comfortably use other loggers and simplify implementing the interface for certain use cases.
currently:
type signalRLogger struct {
zap *zap.Logger
}
func (l *signalRLogger) Log(keyVals ...interface{}) error {
if l.zap == nil {
var err error
l.zap, err = zap.NewDevelopment()
if err != nil {
return err
}
}
lvl := level.DebugValue()
logger := l.zap.Sugar()
for i := 0; i < len(keyVals); i += 2 {
_, isStr := keyVals[i].(string)
if !isStr {
// wtf
continue
}
if keyVals[i] == "ts" {
continue
}
if keyVals[i] == level.Key() {
if gokit, ok := keyVals[i+1].(level.Value); ok {
lvl = gokit
}
continue
}
logger = logger.With(keyVals[i], keyVals[i+1])
}
switch lvl {
case level.DebugValue():
logger.Debug()
case level.InfoValue():
logger.Info()
case level.WarnValue():
logger.Warn()
case level.ErrorValue():
logger.Error()
default:
logger.Error()
}
return nil
}
The current StructuredLogger interface is too basic and requires manually filtering some data, especially the levels
Suggestion:
this allows us to more comfortably use other loggers and simplify implementing the interface for certain use cases.
currently:
proposed: