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

Change set_logger to panic on error #187

Merged
merged 1 commit into from Jul 5, 2017
Merged

Conversation

alisha17
Copy link

There might be more things to fix. But just wanted to get feedback if I am on right track!

Fix to issue #146

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like this is on the right track. Nicely done. Could you check on why the Travis build failed?

Copy link

@mrhota mrhota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks good to me, modulo a few nits and the fix required to pass the build

Thanks @alisha17!

env/src/lib.rs Outdated
Box::new(logger)
})
}

/// Initializes the global logger with an env logger.
///
/// This should be called early in the execution of a Rust program, and the
/// global logger may only be initialized once. Future initialization
/// attempts will return an error.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this comment to say something like "Future initialization attempts will panic." instead of "return an error"?

src/lib.rs Outdated
/// Sets the global logger.
///
/// The `make_logger` closure is passed a `MaxLevel` object, which the
/// logger should use to keep the global maximum log level in sync with the
/// highest log level that the logger will not ignore.
/// highest log level that the logger wills not ignore.
///
/// This function may only be called once in the lifetime of a program. Any log
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should mention that further calls to set_logger after the first will panic.

src/lib.rs Outdated
/// Sets the global logger.
///
/// The `make_logger` closure is passed a `MaxLevel` object, which the
/// logger should use to keep the global maximum log level in sync with the
/// highest log level that the logger will not ignore.
/// highest log level that the logger wills not ignore.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo? should just stay as "logger will not ignore."

src/lib.rs Outdated
@@ -818,11 +818,18 @@ pub fn max_level() -> LevelFilter {
unsafe { mem::transmute(MAX_LOG_LEVEL_FILTER.load(Ordering::Relaxed)) }
}

#[cfg(feature = "use_std")]
pub fn try_set_logger<M>(make_logger: M) -> Result<(), SetLoggerError>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TravisCI complained here about no documentation for this function. Since it's pub, I think it should have some.

Ping me if you want help coming up with some descriptive verbiage for the docs. Although, you can probably just paraphrase the docs from old set_logger

Box::new(Logger(me))
})
.unwrap();
try_set_logger(|max| {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the test only tests the try_ version, you can probably remove the set_logger def at line 18 and the set_logger import in line 9

@@ -33,7 +40,7 @@ impl Log for Logger {

fn main() {
let mut a = None;
set_logger(|max| {
try_set_logger(|max| {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reasoning applies here

env/src/lib.rs Outdated

pub fn init(&mut self) {
let logger = self.build();
let filter = max_level.set(logger.filter());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_level is cause of TravisCI failure, since it doesn't exist in this scope any more.

you can probably change to this-ish:

let logger = self.build();
let filter = logger.filter();
let logger = Box::new(logger); // <---- need to use let again to end previous binding's life, and begin another's
log::set_logger(logger, filter);

warning: I didn't compile that ^^^ so check my work 😄

src/lib.rs Outdated
match try_set_logger(|max| { max.set(filter); logger }) {
Ok(()) => {}
Err(_) => panic!("global logger is already initialized"),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for this function will also need a "# Panics" section to describe the conditions when this function panics.

@alisha17 alisha17 force-pushed the setlogger branch 3 times, most recently from 46c68e8 to d2025e4 Compare June 9, 2017 14:07
@mrhota
Copy link

mrhota commented Jun 11, 2017

@alisha17 TravisCI actually points to line 397, which is in the Logger::init function, not your new Builder::init function. That function expects Builder::init to return a Result, though, and now it just returns a ().

Not sure what the preferred fix is: maybe Logger should get the same treatment the Builder did (try_init and init)?

@brson probably knows better than me

@brson
Copy link
Contributor

brson commented Jun 13, 2017

I agree with @mrhota.

@alisha17 alisha17 force-pushed the setlogger branch 3 times, most recently from a6f61e5 to 088c5eb Compare June 14, 2017 16:26
@alisha17
Copy link
Author

The build is failing. The commit here and the commit in the build do not match. They are different. Is it possible that the test is not triggered for this commit?

@brson
Copy link
Contributor

brson commented Jun 15, 2017

Indeed, both Travis and AppVeyor seem stunningly confused, and I can't seem to unconfuse them.

@brson brson mentioned this pull request Jun 15, 2017
@alisha17
Copy link
Author

@brson Should I create an entirely new PR for this issue?

@brson
Copy link
Contributor

brson commented Jun 15, 2017

No I don't think that will help. I pushed an empty PR to your branch to get the CI to test the new commit. If the tests succeed we can remove that commit again and merge.

@brson
Copy link
Contributor

brson commented Jun 15, 2017

@alisha17 OK, I understand what's happening.

The CI on this repo seems to be set up to merge with master before testing. If you look at the commit it tested, one of the parents is your commit.

The errors it is reporting are legit. Something on master has invalidated one of the test cases when merged with your branch.

What you need to do is rebase your branch on top of the master branch, run the test suite again and fix that error, then force push back to your setlogger branch.

The rebase commands will look something like

git fetch origin
git rebase origin/master
... fix tests ...
git push alisha17 HEAD:setlogger -f

@brson
Copy link
Contributor

brson commented Jun 15, 2017

Here's some documentation about git rebasing if you are not familiar: https://www.atlassian.com/git/tutorials/rewriting-history

@alisha17
Copy link
Author

alisha17 commented Jun 15, 2017

Okay. Done with the rebasing.
When I run the test suite, all tests do pass. It shows no error(with current commit changes).

@brson
Copy link
Contributor

brson commented Jun 15, 2017

@alisha17 You'll need to do a force push to your 'setlogger' branch so that it shows up on this PR.

@alisha17
Copy link
Author

@brson when I force push to my setlogger branch, it shows 'Everything up-to-date'.

@brson
Copy link
Contributor

brson commented Jun 19, 2017

@alisha17 hm, if your local branch is rebased on upsteam master, then pushing to your setlogger branch shouldn't say everything is up to date. Your branch is on 088c5eb, and that is a descendant of a commit from May.

Here's what I see when I rebase your branch and run cargo test: https://gist.github.com/brson/a881e26af9b71b2d4cc981a72944dbb7

I get the same failure as travis does.

@brson
Copy link
Contributor

brson commented Jul 4, 2017

This lgtm now. @sfackler are breaking changes like this ready to be merged in now, or do they need to wait until you are ready for a version bump?

@sfackler
Copy link
Member

sfackler commented Jul 5, 2017

Let's just merge all of the breaking stuff into master - we'll cut an 0.3.x branch off of the last release to do the back compat stuff.

@brson
Copy link
Contributor

brson commented Jul 5, 2017

OK, as far as I can tell this looks right, so I'm merging it. Thanks for your perseverance @alisha17!

@brson brson merged commit f21e9e8 into rust-lang:master Jul 5, 2017
EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
…est-0.11.11

Bump reqwest from 0.11.10 to 0.11.11
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.

None yet

5 participants