-
Notifications
You must be signed in to change notification settings - Fork 260
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
Add an optional logger param #664
base: master
Are you sure you want to change the base?
Changes from all commits
d5061b6
2851f2b
a3f72c8
dd835fe
c300df0
cde2585
2bb47d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a good target to test our new Previously, the global logger state is shared with all the |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,31 +53,31 @@ fn main() { | |
last_log_location: Mutex::new(None), | ||
}); | ||
let a = me.clone(); | ||
set_boxed_logger(Box::new(Logger(me))).unwrap(); | ||
let logger = Logger(me); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we call a log macro with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC it would be One of the rationales is @EFanZh's comment about "binary size", see: |
||
|
||
test_filter(&a, LevelFilter::Off); | ||
test_filter(&a, LevelFilter::Error); | ||
test_filter(&a, LevelFilter::Warn); | ||
test_filter(&a, LevelFilter::Info); | ||
test_filter(&a, LevelFilter::Debug); | ||
test_filter(&a, LevelFilter::Trace); | ||
test_filter(&logger, &a, LevelFilter::Off); | ||
test_filter(&logger, &a, LevelFilter::Error); | ||
test_filter(&logger, &a, LevelFilter::Warn); | ||
test_filter(&logger, &a, LevelFilter::Info); | ||
test_filter(&logger, &a, LevelFilter::Debug); | ||
test_filter(&logger, &a, LevelFilter::Trace); | ||
|
||
test_line_numbers(&a); | ||
test_line_numbers(&logger, &a); | ||
} | ||
} | ||
|
||
fn test_filter(a: &State, filter: LevelFilter) { | ||
fn test_filter(logger: &dyn Log, a: &State, filter: LevelFilter) { | ||
// tests to ensure logs with a level beneath 'max_level' are filtered out | ||
log::set_max_level(filter); | ||
error!(""); | ||
error!(logger: logger, ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'd need to document this behavior. We have a hierarchy of level controls; at compile time, at runtime, and whatever the logger itself applies. We should be clear that these are features of the macros, so apply equally regardless of the logger you plug in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please elaborate a bit what to be documented and where I should add the docs? It seems that you'd like to emphasize that these macros can be compiled to nop if the related flags (e.g., |
||
last(a, t(Level::Error, filter)); | ||
warn!(""); | ||
warn!(logger: logger, ""); | ||
last(a, t(Level::Warn, filter)); | ||
info!(""); | ||
info!(logger: logger, ""); | ||
last(a, t(Level::Info, filter)); | ||
debug!(""); | ||
debug!(logger: logger, ""); | ||
last(a, t(Level::Debug, filter)); | ||
trace!(""); | ||
trace!(logger: logger, ""); | ||
last(a, t(Level::Trace, filter)); | ||
|
||
fn t(lvl: Level, filter: LevelFilter) -> Option<Level> { | ||
|
@@ -93,10 +93,10 @@ fn test_filter(a: &State, filter: LevelFilter) { | |
} | ||
} | ||
|
||
fn test_line_numbers(state: &State) { | ||
fn test_line_numbers(logger: &dyn Log, state: &State) { | ||
log::set_max_level(LevelFilter::Trace); | ||
|
||
info!(""); // ensure check_line function follows log macro | ||
info!(logger: logger, ""); // ensure check_line function follows log macro | ||
check_log_location(state); | ||
|
||
#[track_caller] | ||
|
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.
Shall we
#[inline]
here? In my application development conventions, I trust the compiler to do the inlining based on its analysis.