micro-broker-kgo/logger.go
Vasiliy Tolstov d2ac0c1360
Some checks failed
build / test (push) Failing after 1m49s
codeql / analyze (go) (push) Failing after 2m6s
build / lint (push) Successful in 9m18s
update deps
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-07 00:46:24 +03:00

51 lines
995 B
Go

package kgo
import (
"context"
"github.com/twmb/franz-go/pkg/kgo"
"go.unistack.org/micro/v3/logger"
)
type mlogger struct {
l logger.Logger
ctx context.Context
}
func (l *mlogger) Log(lvl kgo.LogLevel, msg string, args ...interface{}) {
var mlvl logger.Level
switch lvl {
case kgo.LogLevelNone:
return
case kgo.LogLevelError:
mlvl = logger.ErrorLevel
case kgo.LogLevelWarn:
mlvl = logger.WarnLevel
case kgo.LogLevelInfo:
mlvl = logger.InfoLevel
case kgo.LogLevelDebug:
mlvl = logger.DebugLevel
default:
return
}
if len(args) > 0 {
l.l.Log(l.ctx, mlvl, append([]interface{}{msg}, args...)...)
} else {
l.l.Log(l.ctx, mlvl, msg)
}
}
func (l *mlogger) Level() kgo.LogLevel {
switch l.l.Options().Level {
case logger.ErrorLevel:
return kgo.LogLevelError
case logger.WarnLevel:
return kgo.LogLevelWarn
case logger.InfoLevel:
return kgo.LogLevelInfo
case logger.DebugLevel, logger.TraceLevel:
return kgo.LogLevelDebug
}
return kgo.LogLevelNone
}