-
Notifications
You must be signed in to change notification settings - Fork 15
refactor: call flush_atexit at exit #102
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
base: main-dev
Are you sure you want to change the base?
Conversation
Signed-off-by: tison <wander4096@gmail.com>
spdlog/src/logger.rs
Outdated
pub(crate) fn flush_sinks_atexit(&self) { | ||
self.sinks.iter().for_each(|sink| { | ||
if let Err(err) = sink.flush_atexit() { | ||
self.handle_error(err); | ||
} | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be even pub
if users set their own global static LOGGER. But given that is not quite possible it's OK to leave pub(crate)
until real use cases occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea! In fact, previously we still couldn't guarantee that users wouldn't use thread-local (or anything else that might conflict with atexit()
) in their own sinks, because the global atomic bool variable IS_TEARING_DOWN
is not public. This PR enables users to be aware that the program is in an atexit()
callback and customize the flush implementation for this case.
Perhaps one minor nitpick is that I'm not sure if there might be a better choice for the naming. flush_atexit
implies that it will be called in the atexit()
callback, which is good, on the other hand the naming style is not so Rusty... I'll think about it some more, anyway it's not a big issue.
Yeah. I'm struggling with naming this method also. Let's give it some days for potential new ideas :D |
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
What about |
Or even we call the public method simply |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently set atexit
and only hook_panic
if atexit
fails.
However, it seems that atexit
is only called when the process is normally terminated. Not sure if a panic causes a normal exit, or an abnormal exit.
At least when panic = "abort", the atexit glue may not be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not at home these days, will take a look at it days later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not in a rush. Enjoy your days :D
Avoid global static
IS_TEARING_DOWN
trick.