pub struct TreeLogger { /* private fields */ }Implementations§
Source§impl TreeLogger
impl TreeLogger
Sourcepub fn new() -> TreeLogger
pub fn new() -> TreeLogger
Initializes the global logger with a CustomLogger instance with
default log level set to Level::Trace.
use tree_logger::TreeLogger;
TreeLogger::new().with_colors(true).with_threads(true).init().unwrap();
log::warn!("This is an example message.");Examples found in repository?
examples/demo.rs (line 6)
5fn main() {
6 TreeLogger::new()
7 .with_colors(true)
8 .with_threads(true)
9 .with_filter_fn(|data| {
10 match data.elapsed {
11 // Filter out very quick events
12 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 // Optionally we can return a value
42 });
43
44 info!("Profile returns a value: {result}");
45}Sourcepub fn init(self) -> Result<(), SetLoggerError>
pub fn init(self) -> Result<(), SetLoggerError>
Examples found in repository?
examples/demo.rs (line 16)
5fn main() {
6 TreeLogger::new()
7 .with_colors(true)
8 .with_threads(true)
9 .with_filter_fn(|data| {
10 match data.elapsed {
11 // Filter out very quick events
12 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 // Optionally we can return a value
42 });
43
44 info!("Profile returns a value: {result}");
45}Sourcepub fn with_filter_fn(self, filter_fn: fn(&LoggingEvent) -> bool) -> TreeLogger
pub fn with_filter_fn(self, filter_fn: fn(&LoggingEvent) -> bool) -> TreeLogger
Examples found in repository?
examples/demo.rs (lines 9-15)
5fn main() {
6 TreeLogger::new()
7 .with_colors(true)
8 .with_threads(true)
9 .with_filter_fn(|data| {
10 match data.elapsed {
11 // Filter out very quick events
12 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 // Optionally we can return a value
42 });
43
44 info!("Profile returns a value: {result}");
45}pub fn with_level(self, level: LevelFilter) -> TreeLogger
Sourcepub fn with_threads(self, enable_threads: bool) -> TreeLogger
pub fn with_threads(self, enable_threads: bool) -> TreeLogger
Examples found in repository?
examples/demo.rs (line 8)
5fn main() {
6 TreeLogger::new()
7 .with_colors(true)
8 .with_threads(true)
9 .with_filter_fn(|data| {
10 match data.elapsed {
11 // Filter out very quick events
12 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 // Optionally we can return a value
42 });
43
44 info!("Profile returns a value: {result}");
45}Sourcepub fn with_colors(self, enable_colors: bool) -> TreeLogger
pub fn with_colors(self, enable_colors: bool) -> TreeLogger
Control whether messages are colored or not.
Examples found in repository?
examples/demo.rs (line 7)
5fn main() {
6 TreeLogger::new()
7 .with_colors(true)
8 .with_threads(true)
9 .with_filter_fn(|data| {
10 match data.elapsed {
11 // Filter out very quick events
12 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 // Optionally we can return a value
42 });
43
44 info!("Profile returns a value: {result}");
45}pub fn max_level(&self) -> LevelFilter
Trait Implementations§
Source§impl Default for TreeLogger
impl Default for TreeLogger
Auto Trait Implementations§
impl Freeze for TreeLogger
impl RefUnwindSafe for TreeLogger
impl Send for TreeLogger
impl Sync for TreeLogger
impl Unpin for TreeLogger
impl UnwindSafe for TreeLogger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more