remove shutdown and add flush to Log trait #196
No reviewers
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log!196
Loading…
Reference in a new issue
No description provided.
Delete branch "flush"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #117
@danielscottt Wasn't main idea of #117 to remove shutdown? I thought exposing flush functionality was more of a since-we're-in-the-neighborhood sort of thing.
@mrhota It is quite possible that I misunderstood the issue altogether.
r? @sfackler
This synchronization needs to stick around, since
Logisn't anunsafetrait.What would the implementation of
Dropsynchronize on forLoggerGuard? Is the idea to synchronize all__logcalls around flush? Is that how the need forshutdownis removed?The refcounting logic ensures there aren't any log calls actively using the logger while we tear it down, which would be a use-after-free. We can't depend on flush doing this synchronization for us - the default implementation does nothing at all for example!
We're removing shutdown because it's not sufficiently useful compared to its cost in all of this refcounting. The addition of
flushis only semi-related - it's just a way to allow people to make sure that any buffers or whatever are flushed before their application exits so they don't drop messages on the floor.Thanks for the guidance, here! As I feared, I fundamentally misunderstood the ask. I'll clean this up and repush shortly.
@sfackler Perhaps I am totally confused, but why would you need that synchronization? Without shutdown, the logger is never deallocated (or dropped), so we are never going to tear it down?
This is why I left it here after I refactored my first pass, which misunderstood the task. But on account of my initial confusion, I can certainly imagine that I'm missing something.
Also, I think the load/stores from
STATEonly needOrdering::Acquire/ReleasenotSeqCst. UsingSeqCstsynchronizes with any unrelatedSeqCstread/writes somewhere else in the program.Oh, did I totally miss the fact that this PR also removed shutdown? Oops >_>
We should maybe not have a default implementation here?
Write::flushdoes't have a default as a comparison.Thanks for reviewing @sfackler.
The issue mentioned
flushought to have a default implementation, but I'm happy to remove it here. This of course has ramifications forenv_logger; would its implementation be expected to use the same reference counting pattern previously used here when coordinating onshutdown?I'll go ahead and prep a patch that does this in the meantime.
I think the issue mentioned a default impl to retain back compat, which we don't really need to worry about since we're removing shutdown at the same time.
I don't think we'd want to add the refcounting into the flush impl for env_logger - it'd defeat the purpose of getting rid of shutdown in the first place! The use case for flush is when you're for example, in the shutdown process of your application. If you use something like env_logger then just killing the process is fine - any log calls that finished before the exit will end up on the console. But, if you're using a logger that performs the IO asynchronously, you can end up in situations where log lines that should have been output aren't. Imagine something like
All we need to make sure is that the "shutting down" message makes it all the way through the logging infrastructure. If there are other threads doing things in the background, the state of their messages is not super important since they're racing with this thread.
Looks like this is ready to go. Thanks @danielscottt!
@sfackler can you take another look?
Just a couple of tiny tweaks and I think this is good to go!
@ -196,3 +197,2 @@//! # extern crate log;//! # use log::{Level, LevelFilter, SetLoggerError, ShutdownLoggerError,//! # Metadata};//! # use log::{Level, LevelFilter, Log, SetLoggerError, Metadata};Let's just remove this bit of the example.
Looks like we still need to remove the default impl here.
This type can be removed entirely now that we don't need a destructor, but that can be handled later.
Ping @sfackler
Thanks!
Sorry for the very slow review cycle D: