-
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.
Backports #1821 to `v0.1.x`. ## 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 Co-authored-by: Eliza Weisman <[email protected]> Co-authored-by: David Barsky <[email protected]>
- Loading branch information
1 parent
7cf4854
commit 2c3555b
Showing
4 changed files
with
184 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,26 @@ | ||
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 (subscriber, handle) = subscriber::mock() | ||
.with_filter(|meta| { | ||
if meta.target() == "debug_module" { | ||
meta.level() <= &Level::DEBUG | ||
} else { | ||
meta.level() <= &Level::INFO | ||
} | ||
}) | ||
.done() | ||
.run_with_handle(); | ||
|
||
tracing::subscriber::set_global_default(subscriber).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