pub trait LevelAware {
// Required method
fn set_levels(&mut self, _levels: &[Level]) -> &mut Self;
// Provided methods
fn with_levels(self, levels: &[Level]) -> Self
where Self: Sized { ... }
fn set_levels_range(&mut self, from: Level, to: Level) -> &mut Self { ... }
fn with_levels_range(self, from: Level, to: Level) -> Self
where Self: Sized { ... }
}Required Methods§
fn set_levels(&mut self, _levels: &[Level]) -> &mut Self
Provided Methods§
fn with_levels(self, levels: &[Level]) -> Selfwhere
Self: Sized,
fn set_levels_range(&mut self, from: Level, to: Level) -> &mut Self
Sourcefn with_levels_range(self, from: Level, to: Level) -> Selfwhere
Self: Sized,
fn with_levels_range(self, from: Level, to: Level) -> Selfwhere
Self: Sized,
Examples found in repository?
More examples
examples/global.rs (line 31)
27fn main() {
28 astrolog::config(|logger| {
29 logger
30 .set_global("OS", env::consts::OS)
31 .push_handler(ConsoleHandler::new().with_levels_range(Level::Info, Level::Emergency));
32 });
33
34 astrolog::debug("A debug message");
35 astrolog::info("A simple info logging");
36
37 astrolog::with("line", line!())
38 .with("file", file!())
39 .error("An error with some debug info");
40}examples/multithread.rs (line 31)
28fn main() {
29 let logger = Logger::new()
30 .with_global("OS", env::consts::OS)
31 .with_handler(ConsoleHandler::new().with_levels_range(Level::Info, Level::Emergency))
32 .into_arc();
33
34 let ths = (0..10)
35 .map(|i| {
36 let logger = logger.clone();
37 thread::spawn(move || {
38 logger
39 .with("line", line!())
40 .with("file", file!())
41 .with("thread", i)
42 .info("A simple info logging");
43
44 if i % 2 == 0 {
45 logger.with("thread", i).emergency("This thread did something bad");
46 }
47 })
48 })
49 .collect::<Vec<_>>();
50
51 for t in ths {
52 t.join().expect("Thread join failed");
53 }
54}examples/errors.rs (line 77)
74fn main() {
75 let logger = Logger::new()
76 .with_global("OS", env::consts::OS)
77 .with_handler(ConsoleHandler::new().with_levels_range(Level::Info, Level::Emergency));
78
79 let _ = File::open("foo.txt")
80 .map_err(|e| {
81 logger.with_error(&e).error("Simple error opening foo.txt")
82 });
83
84 let _ = File::open("foo.txt")
85 .map_err(|e| {
86 let e_with_trace = MyError::new("Opening foo.txt").with_cause(e);
87 logger.with_error(&e_with_trace).error("Tracing error opening file")
88 });
89
90 let _ = File::open("foo.txt")
91 .map_err(|e| {
92 let e_with_trace = MyError::new("Opening foo.txt").with_cause(MyError::new("second-level error").with_cause(e));
93 logger.with_error(&e_with_trace).error("Deep tracing error opening file")
94 });
95}examples/simple.rs (line 30)
29fn main() {
30 let logger = Logger::new().with_handler(ConsoleHandler::new().with_levels_range(Level::Info, Level::Emergency));
31
32 logger.info("With no context");
33
34 let logger = logger.with_global("OS", env::consts::OS);
35
36 logger.debug("A debug message"); // Will not be printed
37 logger.info("A simple info logging");
38
39 logger
40 .with("line", line!())
41 .with("file", file!())
42 .error("An error with some debug info");
43
44 logger
45 .with_multi(json!({
46 "line": line!(),
47 "file": file!(),
48 }))
49 .critical("This is dangerous!");
50
51 let logger = Logger::new()
52 .with_handler(ConsoleHandler::new()
53 .with_formatter(LineFormatter::new()
54 .with_date_format(DateFormat::Email)
55 .with_level_format(LevelFormat::LowerShort)
56 )
57 );
58
59 logger
60 .with("line", line!())
61 .with("file", file!())
62 .error("An error with custom formatting");
63
64}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".