ziflex / lecho

Zerolog wrapper for Echo framework 🍅
MIT License
97 stars 11 forks source link

Ability save logs to file #17

Open hellodit opened 2 years ago

hellodit commented 2 years ago

Hi, Is lecho have ability to save logs to file with *.log extension?

ziflex commented 2 years ago

try this:

lecho.New(&lumberjack.Logger{
    Filename:   "/var/log/myapp/foo.log",
    MaxSize:    500, // megabytes
    MaxBackups: 3,
    MaxAge:     28, //days
    Compress:   true, // disabled by default
})
rrajkowski commented 1 year ago

Hi @ziflex looking at integrating with an existing Echo app with zerolog and checking if you have plans to integrate the multple output (Stdout, consoleWriter, File)

zerolog.MultiLevelWriter(consoleWriter, os.Stdout)

See docs: https://github.com/rs/zerolog#multiple-log-output

I will take a look at lumberjack example, thanks

ziflex commented 1 year ago

Hey @rrajkowski,

You should be able to do this with the existing API.

lecho.New(zerolog.MultiLevelWriter(consoleWriter, os.Stdout))
lecho.From(zerolog.New(zerolog.MultiLevelWriter(consoleWriter, os.Stdout)))
lecho.Middleware(lecho.Config{
    Logger: lecho.New(zerolog.MultiLevelWriter(consoleWriter, os.Stdout)),
})
rrajkowski commented 1 year ago

@ziflex thanks for the reply. I was able to implement the MultiLevelWriter. I am writting to Stdout and file. I have a new issue added the response from c.Response echo context to the lecho logger.

I've tried the following:

Ideally I can update or modify the logger context with response for a single stdout/file log. I think it would be cool to allow combining of Bodydump and Enricher somehow. I've read through this Zerolog guild but didn't find any working solutions

Let me know and I can move this to a new issue

Thanks