emabee / flexi_logger

A flexible logger for rust programs that can write to stderr, stdout, and/or to log files
Apache License 2.0
315 stars 55 forks source link

Add support for capturing in tests #137

Closed Shatur closed 1 year ago

Shatur commented 1 year ago

I can show logging in tests using the following:

Logger::try_with_env_or_str("info")?.start().ok();

But this way logs will be displayed even in successful tests. It would be great if logs were captured by the rust test system. This way test logs will be displayed only on error or if -- --nocapture is set.

Other popular crate env_logger provides is_test function. This way logs will be printed using println. This is what I proposing to add to flexi_logger as well.

emabee commented 1 year ago

Thanks for creating this issue. I realized the support for cargo test's output capture with a new write mode, WriteMode::SupportCapture.