You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The log_enabled! macro supports a target keyword, to check if logging is enabled with for a given target. The documentation gives this example for instance:
iflog_enabled!(target:"Global",Debug){let data = expensive_call();debug!(target:"Global","expensive debug data: {} {}", data.x, data.y);}
However, the above example would not work correctly when using simplelog as the logging implementation, because simplelogging's implementations of the enabled() method, which log_enabled! depends on, only checks the level, but not the target. So in the above example, if the "Global" target was being filtered out, but the current level was Debug, then the body of the if-statement would still execute. Note, the log! macros themselves do correctly filter on target in addition to level.
Reproduction:
use log::{debug, log_enabled,Level};use simplelog::{ConfigBuilder,LevelFilter,SimpleLogger};fnmain(){SimpleLogger::init(LevelFilter::Debug,ConfigBuilder::new().add_filter_allow_str("foo").build(),).unwrap();iflog_enabled!(target:"bar",Level::Debug){println!("This shouldn't be printed because only target `foo` is enabled, but it will be printed");debug!(target:"bar","This will be correctly filtered out and won't print");}}
The expected behavior is that the whole if-block body would be skipped, but in fact the body is executed.
The text was updated successfully, but these errors were encountered:
The log_enabled! macro supports a
target
keyword, to check if logging is enabled with for a given target. The documentation gives this example for instance:However, the above example would not work correctly when using simplelog as the logging implementation, because simplelogging's implementations of the
enabled()
method, whichlog_enabled!
depends on, only checks the level, but not the target. So in the above example, if the "Global" target was being filtered out, but the current level wasDebug
, then the body of the if-statement would still execute. Note, thelog!
macros themselves do correctly filter on target in addition to level.Reproduction:
The expected behavior is that the whole if-block body would be skipped, but in fact the body is executed.
The text was updated successfully, but these errors were encountered: