Skip to content

Conversation

tisonkun
Copy link
Contributor

@tisonkun tisonkun commented Oct 3, 2025

Avoid global static IS_TEARING_DOWN trick.

Signed-off-by: tison <wander4096@gmail.com>
Comment on lines 473 to 480
pub(crate) fn flush_sinks_atexit(&self) {
self.sinks.iter().for_each(|sink| {
if let Err(err) = sink.flush_atexit() {
self.handle_error(err);
}
});
}

Copy link
Contributor Author

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.

Copy link
Owner

@SpriteOvO SpriteOvO left a 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.

@tisonkun
Copy link
Contributor Author

tisonkun commented Oct 3, 2025

on the other hand the naming style is not so Rusty

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>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

tisonkun commented Oct 5, 2025

What about flush_on_exit?

@tisonkun
Copy link
Contributor Author

tisonkun commented Oct 6, 2025

Or even we call the public method simply exit.

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

2 participants