1use log::{info, warn};
2use std::{thread, time::Duration};
3use tree_logger::{TreeLogger, profile};
4
5fn main() {
6 TreeLogger::new()
7 .with_colors(true)
8 .with_threads(true)
9 .with_filter_fn(|data| {
10 match data.elapsed {
11 Some(elapsed) => elapsed > 5,
13 None => true,
14 }
15 })
16 .init()
17 .unwrap();
18
19 profile!("Super quick event, will be filtered out", || {
20 info!("Can't see me");
21 info!("Can't see me");
22 info!("Can't see me");
23 });
24
25 warn!("Basic warning, not nested, shows up immediately");
26 let result = profile!("First span", || {
27 info!("Info inside a span. Doesn't print until the whole span is done");
28
29 thread::sleep(Duration::from_secs(2));
30
31 profile!("Child span #1", || {
32 info!("Info inside a child span #1");
33 thread::sleep(Duration::from_secs(1));
34 });
35
36 profile!("Child span #2", || {
37 info!("Info inside a child span #2");
38 thread::sleep(Duration::from_secs(1));
39 });
40
41 42 });
43
44 info!("Profile returns a value: {result}");
45}