-
Notifications
You must be signed in to change notification settings - Fork 813
implement Targets::enabled_for
#1903
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ use core::{ | |
slice, | ||
str::FromStr, | ||
}; | ||
use tracing_core::{Interest, Metadata, Subscriber}; | ||
use tracing_core::{Interest, Level, Metadata, Subscriber}; | ||
|
||
/// A filter that enables or disables spans and events based on their [target] | ||
/// and [level]. | ||
|
@@ -313,6 +313,36 @@ impl Targets { | |
Interest::never() | ||
} | ||
} | ||
|
||
/// Returns whether a [target]-[`Level`] pair would be enabled | ||
/// for this `Targets`. | ||
guswynn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// You can use [`module_path!`] from `std` as the target | ||
/// if you want to emulate the behavior of the | ||
/// [`tracing::event!`] suite of macros. | ||
guswynn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use tracing_subscriber::filter::{Targets, LevelFilter}; | ||
/// use tracing_core::Level; | ||
/// | ||
/// let filter = Targets::new() | ||
/// .with_target("my_crate", Level::INFO) | ||
/// .with_target("my_crate::interesting_module", Level::DEBUG); | ||
/// | ||
/// assert!(filter.enabled_for("my_crate", &Level::INFO)); | ||
/// assert!(!filter.enabled_for("my_crate::interesting_module", &Level::TRACE)); | ||
/// ``` | ||
/// | ||
/// [target]: tracing_core::Metadata::target | ||
/// [`tracing::event!`]: tracing::event! | ||
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'm surprised this link needs a reference? 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 am not great at rustdoc links so ill check if its needed 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 took forever to figure out, its not required, but rustdoc doesnt work for this unless |
||
/// [`module_path!`]: std::module_path! | ||
pub fn enabled_for(&self, target: &'static str, level: &Level) -> bool { | ||
guswynn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// "Correct" to call because `Targets` only produces `StaticDirective`'s with NO | ||
// fields | ||
self.0.enabled_for(target, level) | ||
} | ||
} | ||
|
||
impl<T, L> Extend<(T, L)> for Targets | ||
|
Uh oh!
There was an error while loading. Please reload this page.