Skip to content

tracing-appender does not write a single byte #1494

Answered by hawkw
JakkuSakura asked this question in Q&A
Discussion options

You must be logged in to vote

The tracing_appender::non_blocking function returns a non-blocking writer and a drop guard which flushes the writer and shuts it down when dropped. This is intended to be used to ensure the background thread terminates cleanly when the application exits, even in the event of a panic.

However, in order for this to work, the returned guard value has to be held in the program's main function, since dropping it earlier will shut down the writer. In this case, your setup_logs function drops the returned guard as soon as it exits, so the worker thread is shut down immediately.

Try changing your code to something like this, and ensuring that you hold onto the returned guard in your main function:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JakkuSakura
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1493 on August 06, 2021 15:53.