diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:43 +0000 |
commit | 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 (patch) | |
tree | daf049b282ab10e8c3d03e409b3cd84ff3f7690c /vendor/tracing-subscriber/tests/layer_filters/combinators.rs | |
parent | Adding debian version 1.68.2+dfsg1-1. (diff) | |
download | rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.tar.xz rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tracing-subscriber/tests/layer_filters/combinators.rs')
-rw-r--r-- | vendor/tracing-subscriber/tests/layer_filters/combinators.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/tracing-subscriber/tests/layer_filters/combinators.rs b/vendor/tracing-subscriber/tests/layer_filters/combinators.rs new file mode 100644 index 000000000..6052a2d00 --- /dev/null +++ b/vendor/tracing-subscriber/tests/layer_filters/combinators.rs @@ -0,0 +1,42 @@ +use super::*; +use tracing_subscriber::{ + filter::{filter_fn, FilterExt, LevelFilter}, + prelude::*, +}; + +#[test] +fn and() { + let (layer, handle) = layer::mock() + .event( + event::msg("a very interesting event") + .at_level(tracing::Level::INFO) + .with_target("interesting_target"), + ) + .done() + .run_with_handle(); + + // Enables spans and events with targets starting with `interesting_target`: + let target_filter = filter::filter_fn(|meta| meta.target().starts_with("interesting_target")); + + // Enables spans and events with levels `INFO` and below: + let level_filter = LevelFilter::INFO; + + // Combine the two filters together, returning a filter that only enables + // spans and events that *both* filters will enable: + let filter = target_filter.and(level_filter); + + let _subscriber = tracing_subscriber::registry() + .with(layer.with_filter(filter)) + .set_default(); + + // This event will *not* be enabled: + tracing::info!("an event with an uninteresting target"); + + // This event *will* be enabled: + tracing::info!(target: "interesting_target", "a very interesting event"); + + // This event will *not* be enabled: + tracing::debug!(target: "interesting_target", "interesting debug event..."); + + handle.assert_finished(); +} |