Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upremove shutdown and add `flush` to `Log` trait #196
Conversation
pittma
force-pushed the
pittma:flush
branch
from
6ab6756
to
c3ded0a
Jun 5, 2017
This comment has been minimized.
This comment has been minimized.
mrhota
commented
Jun 6, 2017
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
@mrhota It is quite possible that I misunderstood the issue altogether. |
This comment has been minimized.
This comment has been minimized.
|
r? @sfackler |
sfackler
reviewed
Jun 19, 2017
| @@ -1153,12 +1155,6 @@ mod panic { | |||
|
|
|||
| struct LoggerGuard(&'static Log); | |||
|
|
|||
| impl Drop for LoggerGuard { | |||
This comment has been minimized.
This comment has been minimized.
sfackler
Jun 19, 2017
Member
This synchronization needs to stick around, since Log isn't an unsafe trait.
This comment has been minimized.
This comment has been minimized.
pittma
Jun 20, 2017
Author
Contributor
What would the implementation of Drop synchronize on for LoggerGuard? Is the idea to synchronize all __log calls around flush? Is that how the need for shutdown is removed?
This comment has been minimized.
This comment has been minimized.
sfackler
Jun 20, 2017
Member
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 flush is 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.
This comment has been minimized.
This comment has been minimized.
pittma
Jun 20, 2017
Author
Contributor
Thanks for the guidance, here! As I feared, I fundamentally misunderstood the ask. I'll clean this up and repush shortly.
This comment has been minimized.
This comment has been minimized.
manuthambi
Jun 28, 2017
@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 comment has been minimized.
This comment has been minimized.
pittma
Jun 28, 2017
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
manuthambi
Jun 29, 2017
Also, I think the load/stores from STATE only need Ordering::Acquire/Release not SeqCst. Using SeqCst synchronizes with any unrelated SeqCst read/writes somewhere else in the program.
This comment has been minimized.
This comment has been minimized.
sfackler
Jun 29, 2017
Member
Oh, did I totally miss the fact that this PR also removed shutdown? Oops >_>
pittma
force-pushed the
pittma:flush
branch
from
c3ded0a
to
1ed8201
Jun 20, 2017
pittma
changed the title
add `flush` to `Log` trait
remove shutdown and add `flush` to `Log` trait
Jun 20, 2017
sfackler
reviewed
Jun 29, 2017
| @@ -716,6 +692,9 @@ pub trait Log: Sync + Send { | |||
| /// Implementations of `log` should perform all necessary filtering | |||
| /// internally. | |||
| fn log(&self, record: &Record); | |||
|
|
|||
| /// Flushes any buffered records. | |||
| fn flush(&self) {} | |||
This comment has been minimized.
This comment has been minimized.
sfackler
Jun 29, 2017
Member
We should maybe not have a default implementation here? Write::flush does't have a default as a comparison.
This comment has been minimized.
This comment has been minimized.
pittma
Jul 6, 2017
•
Author
Contributor
The issue mentioned flush ought to have a default implementation, but I'm happy to remove it here. This of course has ramifications for env_logger; would its implementation be expected to use the same reference counting pattern previously used here when coordinating on shutdown?
This comment has been minimized.
This comment has been minimized.
pittma
Jul 6, 2017
Author
Contributor
I'll go ahead and prep a patch that does this in the meantime.
This comment has been minimized.
This comment has been minimized.
sfackler
Jul 6, 2017
Member
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
info!("shutting down");
log::flush();
process::exit(0);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.
This comment has been minimized.
This comment has been minimized.
|
Thanks for reviewing @sfackler. |
pittma
force-pushed the
pittma:flush
branch
3 times, most recently
from
5ddba76
to
4aa4c9d
Jul 6, 2017
This comment has been minimized.
This comment has been minimized.
|
Looks like this is ready to go. Thanks @danielscottt! @sfackler can you take another look? |
sfackler
reviewed
Jul 15, 2017
|
Just a couple of tiny tweaks and I think this is good to go! |
| //! let logger = unsafe { &*(logger as *const SimpleLogger) }; | ||
| //! logger.flush(); | ||
| //! }) | ||
| //! pub fn shutdown() { |
This comment has been minimized.
This comment has been minimized.
| @@ -1178,12 +1092,6 @@ mod panic { | |||
|
|
|||
| struct LoggerGuard(&'static Log); | |||
This comment has been minimized.
This comment has been minimized.
sfackler
Jul 15, 2017
Member
This type can be removed entirely now that we don't need a destructor, but that can be handled later.
| @@ -715,6 +696,9 @@ pub trait Log: Sync + Send { | |||
| /// Implementations of `log` should perform all necessary filtering | |||
| /// internally. | |||
| fn log(&self, record: &Record); | |||
|
|
|||
| /// Flushes any buffered records. | |||
| fn flush(&self) {} | |||
This comment has been minimized.
This comment has been minimized.
pittma
force-pushed the
pittma:flush
branch
from
4aa4c9d
to
e66665f
Jul 17, 2017
pittma
force-pushed the
pittma:flush
branch
from
e66665f
to
44bbdbd
Jul 17, 2017
This comment has been minimized.
This comment has been minimized.
|
Ping @sfackler |
sebasmagri
referenced this pull request
Aug 4, 2017
Closed
Remove env_logger from this repository #145
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Sorry for the very slow review cycle D: |
pittma commentedJun 5, 2017
•
edited
Fixes #117