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
Conversation
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, looks like this is on the right track. Nicely done. Could you check on why the Travis build failed?
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.
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. |
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.
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 |
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.
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. |
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.
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> |
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.
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| { |
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.
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| { |
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.
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()); |
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.
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"), | ||
} | ||
} |
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.
The docs for this function will also need a "# Panics" section to describe the conditions when this function panics.
46c68e8
to
d2025e4
Compare
@alisha17 TravisCI actually points to line 397, which is in the Not sure what the preferred fix is: maybe @brson probably knows better than me |
I agree with @mrhota. |
a6f61e5
to
088c5eb
Compare
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? |
Indeed, both Travis and AppVeyor seem stunningly confused, and I can't seem to unconfuse them. |
@brson Should I create an entirely new PR for this issue? |
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. |
@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 The rebase commands will look something like
|
Here's some documentation about git rebasing if you are not familiar: https://www.atlassian.com/git/tutorials/rewriting-history |
Okay. Done with the rebasing. |
@alisha17 You'll need to do a force push to your 'setlogger' branch so that it shows up on this PR. |
@brson when I force push to my setlogger branch, it shows 'Everything up-to-date'. |
@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 I get the same failure as travis does. |
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? |
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. |
OK, as far as I can tell this looks right, so I'm merging it. Thanks for your perseverance @alisha17! |
…est-0.11.11 Bump reqwest from 0.11.10 to 0.11.11
There might be more things to fix. But just wanted to get feedback if I am on right track!
Fix to issue #146