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

How to flush the logger. #33

Closed
sedrik opened this issue Mar 1, 2021 · 4 comments
Closed

How to flush the logger. #33

sedrik opened this issue Mar 1, 2021 · 4 comments

Comments

@sedrik
Copy link

sedrik commented Mar 1, 2021

I am trying to setup a AWS Lambda where I wanted to use simple_logger as my logging facility but it seems that I need to flush the logger before the lambda shutsdown otherwise I will get buffered but not yet written messages printed in the lamda logs.

The log::Log trait does expose a flush method but as init only returns a unit value I do not have access to the flogger to call flush on it.

Is this an oversight or should I look for a different library for my logging needs?

@piegamesde
Copy link
Contributor

I'd say this is an oversight: https://github.com/borntyping/rust-simple_logger/blob/master/src/lib.rs#L233

As this logger only writes to stdout, I think you can work around this by flushing it instead.

@sedrik
Copy link
Author

sedrik commented Mar 2, 2021

Yeah worked around it by flushing stdout. If possible flushing on Drop might be a decent solution?

@borntyping
Copy link
Owner

The Log trait now has a flush() method. It's been a while, but hopefully this fixes your issue if it's still a problem.

use simple_logger::SimpleLogger;

fn main() {
    SimpleLogger::new().init().unwrap();

    log::warn!("This is an example message.");

    log::logger().flush();
}

80c236b

@sedrik
Copy link
Author

sedrik commented Aug 21, 2022

Thanks I have been using the workaround to flush stdout but will switch over to this the next time I need to update the lambda in question. :)

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

No branches or pull requests

3 participants