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 upChange set_logger to panic on error #187
Conversation
alisha17
force-pushed the
alisha17:setlogger
branch
from
a7bfae7
to
c32c1bf
May 31, 2017
dtolnay
reviewed
Jun 2, 2017
|
Thanks, looks like this is on the right track. Nicely done. Could you check on why the Travis build failed? |
mrhota
reviewed
Jun 3, 2017
| 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. |
This comment has been minimized.
This comment has been minimized.
mrhota
Jun 3, 2017
Can you change this comment to say something like "Future initialization attempts will panic." instead of "return an error"?
| /// 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 |
This comment has been minimized.
This comment has been minimized.
| /// 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 comment has been minimized.
This comment has been minimized.
| @@ -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> | |||
This comment has been minimized.
This comment has been minimized.
mrhota
Jun 3, 2017
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| { |
This comment has been minimized.
This comment has been minimized.
mrhota
Jun 3, 2017
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| { | |||
This comment has been minimized.
This comment has been minimized.
|
|
||
| pub fn init(&mut self) { | ||
| let logger = self.build(); | ||
| let filter = max_level.set(logger.filter()); |
This comment has been minimized.
This comment has been minimized.
mrhota
Jun 3, 2017
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
brson
reviewed
Jun 3, 2017
| match try_set_logger(|max| { max.set(filter); logger }) { | ||
| Ok(()) => {} | ||
| Err(_) => panic!("global logger is already initialized"), | ||
| } | ||
| } |
This comment has been minimized.
This comment has been minimized.
brson
Jun 3, 2017
Contributor
The docs for this function will also need a "# Panics" section to describe the conditions when this function panics.
alisha17
force-pushed the
alisha17:setlogger
branch
3 times, most recently
from
46c68e8
to
d2025e4
Jun 9, 2017
This comment has been minimized.
This comment has been minimized.
mrhota
commented
Jun 11, 2017
•
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
I agree with @mrhota. |
alisha17
force-pushed the
alisha17:setlogger
branch
3 times, most recently
from
a6f61e5
to
088c5eb
Jun 14, 2017
This comment has been minimized.
This comment has been minimized.
|
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
force-pushed the
alisha17:setlogger
branch
from
2989faf
to
088c5eb
Jun 15, 2017
This comment has been minimized.
This comment has been minimized.
|
Indeed, both Travis and AppVeyor seem stunningly confused, and I can't seem to unconfuse them. |
This comment has been minimized.
This comment has been minimized.
|
@brson Should I create an entirely new PR for this issue? |
This comment has been minimized.
This comment has been minimized.
|
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
force-pushed the
alisha17:setlogger
branch
from
5609045
to
088c5eb
Jun 15, 2017
This comment has been minimized.
This comment has been minimized.
|
@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
|
This comment has been minimized.
This comment has been minimized.
|
Here's some documentation about git rebasing if you are not familiar: https://www.atlassian.com/git/tutorials/rewriting-history |
This comment has been minimized.
This comment has been minimized.
|
Okay. Done with the rebasing. |
This comment has been minimized.
This comment has been minimized.
|
@alisha17 You'll need to do a force push to your 'setlogger' branch so that it shows up on this PR. |
This comment has been minimized.
This comment has been minimized.
|
@brson when I force push to my setlogger branch, it shows 'Everything up-to-date'. |
This comment has been minimized.
This comment has been minimized.
|
@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. |
alisha17
force-pushed the
alisha17:setlogger
branch
from
e630108
to
a1e0bca
Jun 22, 2017
alisha17
referenced this pull request
Jun 26, 2017
Closed
Rename set_logger_raw to try_set_logger_raw #204
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
OK, as far as I can tell this looks right, so I'm merging it. Thanks for your perseverance @alisha17! |
alisha17 commentedMay 31, 2017
There might be more things to fix. But just wanted to get feedback if I am on right track!
Fix to issue #146