0

I have a struct requesting a standard log.Logger as parameter for log messages. From the zap logger a wrapper is provided by NewStdLogAt:

stdLogAt, err := zap.NewStdLogAt(&s.log, zap.ErrorLevel)

Now I have to use this module in a logrus logger environment. I have not found logrus providing an implementation for log.Logger. What are my possible approaches? Is there an implementation available?

k_o_
  • 5,143
  • 1
  • 34
  • 43

1 Answers1

1

The Logrus documentation seems to suggest creating a new log.Logger using the result of the Writer function which Logrus loggers and entries provide.

w := logrusLogger.Writer()

// or to define an error level:
// logrusLogger.WriterLevel(logrus.ErrorLevel)

// note that you are responsible for closing the writer
defer w.Close() 

stdlibLogger := log.New(w, "", 0)

I have inferred this from the "Logger as an io.Writer" section on this page.

k_o_
  • 5,143
  • 1
  • 34
  • 43
phonaputer
  • 1,485
  • 4
  • 9