1 use tracing::Level; 2 use tracing_mock::*; 3 4 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] 5 #[test] max_level_hints()6fn max_level_hints() { 7 // This test asserts that when a subscriber provides us with the global 8 // maximum level that it will enable (by implementing the 9 // `Subscriber::max_level_hint` method), we will never call 10 // `Subscriber::enabled` for events above that maximum level. 11 // 12 // In this case, we test that by making the `enabled` method assert that no 13 // `Metadata` for spans or events at the `TRACE` or `DEBUG` levels. 14 let (subscriber, handle) = subscriber::mock() 15 .with_max_level_hint(Level::INFO) 16 .with_filter(|meta| { 17 assert!( 18 dbg!(meta).level() <= &Level::INFO, 19 "a TRACE or DEBUG event was dynamically filtered: " 20 ); 21 true 22 }) 23 .event(expect::event().at_level(Level::INFO)) 24 .event(expect::event().at_level(Level::WARN)) 25 .event(expect::event().at_level(Level::ERROR)) 26 .only() 27 .run_with_handle(); 28 29 tracing::subscriber::set_global_default(subscriber).unwrap(); 30 31 tracing::info!("doing a thing that you might care about"); 32 tracing::debug!("charging turboencabulator with interocitor"); 33 tracing::warn!("extremely serious warning, pay attention"); 34 tracing::trace!("interocitor charge level is 10%"); 35 tracing::error!("everything is on fire"); 36 handle.assert_finished(); 37 } 38