-
Notifications
You must be signed in to change notification settings - Fork 15
Flush sinks on program exit with a special method Sink::flush_on_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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
45128ef
refactor: call flush_atexit at exit
tisonkun ce175c2
Update spdlog/src/sink/async_sink/async_pool_sink.rs
tisonkun 3e52f81
forward flush_atexit to DedupSink
tisonkun 6cb4df9
fixup
tisonkun baa32e9
simplify code
tisonkun e37ae9f
carry out clippy workaround
tisonkun 1e4304a
fixup
tisonkun fb89450
rename flush_atexit to flush_on_exit
tisonkun 4c62e5f
More detailed documentation for `Sink::flush_on_exit`
SpriteOvO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -470,6 +470,14 @@ impl Logger { | |
| }) | ||
| } | ||
|
|
||
| pub(crate) fn flush_sinks_atexit(&self) { | ||
| self.sinks.iter().for_each(|sink| { | ||
| if let Err(err) = sink.flush_atexit() { | ||
| self.handle_error(err); | ||
| } | ||
| }); | ||
| } | ||
SpriteOvO marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
||
| // This will lose the periodic flush property, if any. | ||
| #[must_use] | ||
| fn clone_lossy(&self) -> Self { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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 currently set
atexitand onlyhook_panicifatexitfails.However, it seems that
atexitis 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
Uh oh!
There was an error while loading. Please reload this page.
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.
For "unwind" panic,
atexitcallbacks will be called. But I didn't realize "abort" panic before, and indeed as you said,atexitdoesn't work for it.I'm not sure yet what the best solution for it is, maybe always hook panic if
#[cfg(panic = "abort")]? Because we don't need the callback to be called twice (once fromatexitand once from the panic handler). Anyway, I think this should be implemented in a new PR, not in this one. But it's valuable that you mentioned it, soflush_atexitis really not a good name, if the panic handler is actually calling it.I think
flush_on_exitis fine. Also, I've been thinking about the need to add an exit reason parameter:One reason is that it may be possible in the future, we call flush when a crash signal occurs (we had an attempt in PR #18), and there are stricter safety requirements (signal-safety) for exception signals, in short, many APIs can't be used in some signal handlers.
Not sure if such a parameter is necessary to add, and to add it now.
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.
Thanks for your update. I'll give this PR another round early next month.