-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Motivation Closes: #1668 My usecase is different than the referenced "avoid doing something expensive to log": I want to guard turning on `debug` mode for an ffi'd library, based on some `target` that represents the "module" we care about. ## Solution The macro is very similar to `event!`, but adds a few simplistic cases, and generates ever so slightly different code (to return the correct value always. It also skips anything to do with `tracing-log`. I considered (and tried), to share the impl between `event!` and `enabled!`, but must confess I am not good at macros and got stuck. I think they are sufficiently different, where copied impls, is easier to read. We already manage Also, my project is on the crates.io version, so this would need to be backported to 0.1, I can help with that with guidance. Co-authored-by: Eliza Weisman <[email protected]> Co-authored-by: David Barsky <[email protected]>
- Loading branch information
1 parent
820613c
commit 71da8a5
Showing
4 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// liballoc is required because the test subscriber cannot be constructed | ||
// statically | ||
#![cfg(feature = "alloc")] | ||
|
||
mod support; | ||
|
||
use self::support::*; | ||
use tracing::Level; | ||
|
||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] | ||
#[test] | ||
fn level_and_target() { | ||
let (collector, handle) = collector::mock() | ||
.with_filter(|meta| { | ||
if meta.target() == "debug_module" { | ||
meta.level() <= &Level::DEBUG | ||
} else { | ||
meta.level() <= &Level::INFO | ||
} | ||
}) | ||
.done() | ||
.run_with_handle(); | ||
|
||
tracing::collect::set_global_default(collector).unwrap(); | ||
|
||
assert!(tracing::enabled!(target: "debug_module", Level::DEBUG)); | ||
assert!(tracing::enabled!(Level::ERROR)); | ||
assert!(!tracing::enabled!(Level::DEBUG)); | ||
handle.assert_finished(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters