Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability save logs to file #17

Open
hellodit opened this issue May 12, 2022 · 4 comments
Open

Ability save logs to file #17

hellodit opened this issue May 12, 2022 · 4 comments
Labels
question Further information is requested

Comments

@hellodit
Copy link

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

@ziflex
Copy link
Owner

ziflex commented Aug 3, 2022

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
})

@ziflex ziflex added the question Further information is requested label Aug 3, 2022
@rrajkowski
Copy link

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
Copy link
Owner

ziflex commented Mar 9, 2023

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
Copy link

rrajkowski commented Mar 9, 2023

@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:

Enricher: func(c echo.Context, logger zerolog.Context) zerolog.Context {
            return e.Interface("response", c.Response())
        }, 

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants