emabee / flexi_logger

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

Missing log records at the end #71

Closed nalply closed 3 years ago

nalply commented 3 years ago

Not a bug report but an end-user question:

Sometimes my program or my test seems to have ended already before all has been logged. The symptom is that sometimes the last few logging records are missing.

What should I do? Somehow get the logging thread then wait for it to end?

I tried thread::yield_now(), thread::sleep(), io::stderr().lock().flush(), etc., but sometimes records are still missing. Often an additional strategic dummy info!() somewhere helps.

nalply commented 3 years ago

Solved by: log_target(flexi_logger::LogTarget::StdOut). Perhaps it's the terminal of vscode messing things up.

emabee commented 3 years ago

Hm, a bit strange. So far flexi_logger logs synchronously, there is no async-logging (yet). By default, flexi_logger logs to stderr, and flushes stderr before being ended. But I found that the flush was missing for stdout! You described it right the other way - could you please check once more?