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

Improvements #2

Merged
merged 5 commits into from
Sep 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not require .init() to be called.
Use the verbosity which is stored to check if a level is enabled
Dr-Emann committed Sep 3, 2017
commit ecb7f3699a947bae6aa3a665beb72ad98757b86c
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ pub struct StdErrLog {

impl log::Log for StdErrLog {
fn enabled(&self, metadata: &LogMetadata) -> bool {
metadata.level() <= log::max_log_level()
metadata.level() <= self.log_level_filter()
}

fn log(&self, record: &log::LogRecord) {
@@ -164,14 +164,18 @@ impl StdErrLog {
self
}

fn log_level_filter(&self) -> LogLevelFilter {
if self.quiet {
LogLevelFilter::Off
} else {
self.verbosity
}
}

pub fn init(&self) -> Result<(), log::SetLoggerError> {

log::set_logger(|max_log_level| {
if self.quiet {
max_log_level.set(LogLevelFilter::Off);
} else {
max_log_level.set(self.verbosity);
}
max_log_level.set(self.log_level_filter());

Box::new(self.clone())
})