Skip to content
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

remove shutdown and add `flush` to `Log` trait #196

Merged
merged 1 commit into from Aug 10, 2017

Conversation

Projects
None yet
6 participants
@pittma
Copy link
Contributor

pittma commented Jun 5, 2017

Fixes #117

@pittma pittma force-pushed the pittma:flush branch from 6ab6756 to c3ded0a Jun 5, 2017

@mrhota

This comment has been minimized.

Copy link

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.

@pittma

This comment has been minimized.

Copy link
Contributor Author

pittma commented Jun 6, 2017

@mrhota It is quite possible that I misunderstood the issue altogether.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 19, 2017

src/lib.rs Outdated
@@ -1153,12 +1155,6 @@ mod panic {

struct LoggerGuard(&'static Log);

impl Drop for LoggerGuard {

This comment has been minimized.

@sfackler

sfackler Jun 19, 2017

Member

This synchronization needs to stick around, since Log isn't an unsafe trait.

This comment has been minimized.

@pittma

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.

@sfackler

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.

@pittma

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.

@manuthambi

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.

@pittma

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.

@manuthambi

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.

@sfackler

sfackler Jun 29, 2017

Member

Oh, did I totally miss the fact that this PR also removed shutdown? Oops >_>

@pittma pittma force-pushed the pittma:flush branch from c3ded0a to 1ed8201 Jun 20, 2017

@pittma pittma changed the title add `flush` to `Log` trait remove shutdown and add `flush` to `Log` trait Jun 20, 2017

src/lib.rs Outdated
@@ -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.

@sfackler

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.

@pittma

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.

@pittma

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.

@sfackler

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.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jul 6, 2017

Thanks for reviewing @sfackler.

@pittma pittma force-pushed the pittma:flush branch 3 times, most recently from 5ddba76 to 4aa4c9d Jul 6, 2017

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jul 15, 2017

Looks like this is ready to go. Thanks @danielscottt!

@sfackler can you take another look?

@sfackler
Copy link
Member

sfackler left a comment

Just a couple of tiny tweaks and I think this is good to go!

src/lib.rs Outdated
//! let logger = unsafe { &*(logger as *const SimpleLogger) };
//! logger.flush();
//! })
//! pub fn shutdown() {

This comment has been minimized.

@sfackler

sfackler Jul 15, 2017

Member

Let's just remove this bit of the example.

src/lib.rs Outdated
@@ -1178,12 +1092,6 @@ mod panic {

struct LoggerGuard(&'static Log);

This comment has been minimized.

@sfackler

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.

src/lib.rs Outdated
@@ -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.

@sfackler

sfackler Jul 15, 2017

Member

Looks like we still need to remove the default impl here.

@pittma pittma force-pushed the pittma:flush branch from 4aa4c9d to e66665f Jul 17, 2017

dan pittman
removes shutdown and adds `flush` to Log trait.
Signed-off-by: dan pittman <danielscottt@gmail.com>

@pittma pittma force-pushed the pittma:flush branch from e66665f to 44bbdbd Jul 17, 2017

@aturon

This comment has been minimized.

Copy link
Contributor

aturon commented Aug 2, 2017

Ping @sfackler

@sebasmagri sebasmagri referenced this pull request Aug 4, 2017

Closed

Remove env_logger from this repository #145

2 of 2 tasks complete
@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Aug 10, 2017

Thanks!

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Aug 10, 2017

Sorry for the very slow review cycle D:

@sfackler sfackler merged commit 4fb1ee8 into rust-lang-nursery:master Aug 10, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

mjkillough added a commit to mjkillough/env_logger that referenced this pull request Aug 21, 2017

mjkillough added a commit to mjkillough/env_logger that referenced this pull request Aug 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.