1 use tracing::subscriber::with_default; 2 use tracing::Level; 3 use tracing_attributes::instrument; 4 use tracing_mock::*; 5 6 #[test] named_levels()7fn named_levels() { 8 #[instrument(level = "trace")] 9 fn trace() {} 10 11 #[instrument(level = "Debug")] 12 fn debug() {} 13 14 #[instrument(level = "INFO")] 15 fn info() {} 16 17 #[instrument(level = "WARn")] 18 fn warn() {} 19 20 #[instrument(level = "eRrOr")] 21 fn error() {} 22 let (subscriber, handle) = subscriber::mock() 23 .new_span(span::mock().named("trace").at_level(Level::TRACE)) 24 .enter(span::mock().named("trace").at_level(Level::TRACE)) 25 .exit(span::mock().named("trace").at_level(Level::TRACE)) 26 .new_span(span::mock().named("debug").at_level(Level::DEBUG)) 27 .enter(span::mock().named("debug").at_level(Level::DEBUG)) 28 .exit(span::mock().named("debug").at_level(Level::DEBUG)) 29 .new_span(span::mock().named("info").at_level(Level::INFO)) 30 .enter(span::mock().named("info").at_level(Level::INFO)) 31 .exit(span::mock().named("info").at_level(Level::INFO)) 32 .new_span(span::mock().named("warn").at_level(Level::WARN)) 33 .enter(span::mock().named("warn").at_level(Level::WARN)) 34 .exit(span::mock().named("warn").at_level(Level::WARN)) 35 .new_span(span::mock().named("error").at_level(Level::ERROR)) 36 .enter(span::mock().named("error").at_level(Level::ERROR)) 37 .exit(span::mock().named("error").at_level(Level::ERROR)) 38 .done() 39 .run_with_handle(); 40 41 with_default(subscriber, || { 42 trace(); 43 debug(); 44 info(); 45 warn(); 46 error(); 47 }); 48 49 handle.assert_finished(); 50 } 51 52 #[test] numeric_levels()53fn numeric_levels() { 54 #[instrument(level = 1)] 55 fn trace() {} 56 57 #[instrument(level = 2)] 58 fn debug() {} 59 60 #[instrument(level = 3)] 61 fn info() {} 62 63 #[instrument(level = 4)] 64 fn warn() {} 65 66 #[instrument(level = 5)] 67 fn error() {} 68 let (subscriber, handle) = subscriber::mock() 69 .new_span(span::mock().named("trace").at_level(Level::TRACE)) 70 .enter(span::mock().named("trace").at_level(Level::TRACE)) 71 .exit(span::mock().named("trace").at_level(Level::TRACE)) 72 .new_span(span::mock().named("debug").at_level(Level::DEBUG)) 73 .enter(span::mock().named("debug").at_level(Level::DEBUG)) 74 .exit(span::mock().named("debug").at_level(Level::DEBUG)) 75 .new_span(span::mock().named("info").at_level(Level::INFO)) 76 .enter(span::mock().named("info").at_level(Level::INFO)) 77 .exit(span::mock().named("info").at_level(Level::INFO)) 78 .new_span(span::mock().named("warn").at_level(Level::WARN)) 79 .enter(span::mock().named("warn").at_level(Level::WARN)) 80 .exit(span::mock().named("warn").at_level(Level::WARN)) 81 .new_span(span::mock().named("error").at_level(Level::ERROR)) 82 .enter(span::mock().named("error").at_level(Level::ERROR)) 83 .exit(span::mock().named("error").at_level(Level::ERROR)) 84 .done() 85 .run_with_handle(); 86 87 with_default(subscriber, || { 88 trace(); 89 debug(); 90 info(); 91 warn(); 92 error(); 93 }); 94 95 handle.assert_finished(); 96 } 97