logger: add Logger method to access *logrus.Logger

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2022-10-18 18:26:39 +02:00
parent c7096975b1
commit 23f1b78389
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF

View File

@ -64,6 +64,7 @@ type Logger interface {
Logr() logr.Logger
FieldLogger() logrus.FieldLogger
Logger() *logrus.Logger
}
type logger struct {
@ -167,25 +168,12 @@ func (l *logger) Panicln(args ...interface{}) {
}
func (l *logger) WriterLevel(level logrus.Level) *io.PipeWriter {
switch t := l.fl.(type) {
case *logrus.Logger:
return t.WriterLevel(level)
case *logrus.Entry:
return t.WriterLevel(level)
}
panic(fmt.Sprintf("unexpected logger type %T", l.fl))
return l.Logger().WriterLevel(level)
}
func (l *logger) SetLevel(level logrus.Level) Logger {
switch t := l.fl.(type) {
case *logrus.Logger:
t.SetLevel(level)
l.Logger().SetLevel(level)
return l
case *logrus.Entry:
t.Logger.SetLevel(level)
return l
}
panic(fmt.Sprintf("unexpected logger type %T", l.fl))
}
func (l *logger) WithField(key string, value interface{}) Logger {
@ -212,14 +200,17 @@ func (l *logger) FieldLogger() logrus.FieldLogger {
return l.fl
}
func (l *logger) SetOutput(w io.Writer) Logger {
func (l *logger) Logger() *logrus.Logger {
switch t := l.fl.(type) {
case *logrus.Logger:
t.SetOutput(w)
return l
return t
case *logrus.Entry:
t.Logger.SetOutput(w)
return l
return t.Logger
}
panic(fmt.Sprintf("unexpected logger type %T", l.fl))
}
func (l *logger) SetOutput(w io.Writer) Logger {
l.Logger().SetOutput(w)
return l
}