phuslu / log

Fastest structured logging
MIT License
672 stars 44 forks source link

How to use it with echo ? #25

Closed pankajsoni19 closed 3 years ago

pankajsoni19 commented 3 years ago

I am on echo v4

Logger = log.Logger{
        Level: log.InfoLevel,
        Writer: &log.AsyncWriter{
            ChannelSize: 100,
            Writer:      fileWriter,
        },
    }

logConfig := middleware.DefaultLoggerConfig
logConfig.Output = Logger   // error here
e.Use(middleware.LoggerWithConfig(logConfig))  

Error is

cannot use Logger.Writer (variable of type log.Writer) as io.Writer value in assignment: missing method Writecompiler
phuslu commented 3 years ago

the simplest way is

logConfig.Output = Logger.Std(log.InfoLevel, nil, "", stdLog.LstdFlags).Writer()

But a formal way is you should write a structured style logger like https://github.com/phuslu/log/issues/22

pankajsoni19 commented 3 years ago

I saw FileWriter it implements io.Writer. I just used fileWriter without the async wrapper.

logConfig := middleware.DefaultLoggerConfig
logConfig.Output = global.Logger.Writer.(*log.FileWriter)
e.Use(middleware.LoggerWithConfig(logConfig))
phuslu commented 3 years ago

Yes, it's also works. except it directly write plan text output nor structured output to writer.