diff --git a/logger/logger.go b/logger/logger.go index 77d2b4c..51a5666 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,6 +1,7 @@ package logger import ( + "context" "fmt" "io" @@ -26,6 +27,8 @@ func FromLogrus(fl logrus.Ext1FieldLogger) Logger { } type Logger interface { + WithContext(ctx context.Context) Logger + WithField(key string, value interface{}) Logger WithFields(kv ...interface{}) Logger WithError(err error) Logger @@ -191,6 +194,16 @@ func (l *logger) SetLevel(level logrus.Level) Logger { return l } +func (l *logger) WithContext(ctx context.Context) Logger { + switch t := l.fl.(type) { + case *logrus.Logger: + return &logger{fl: t.WithContext(ctx)} + case *logrus.Entry: + return &logger{fl: t.WithContext(ctx)} + } + panic(fmt.Sprintf("unexpected logger type %T", l.fl)) +} + func (l *logger) WithField(key string, value interface{}) Logger { return &logger{fl: l.fl.WithField(key, value)} }