1use traccia::{Hook, LogLevel, TargetId, info, warn};
2
3fn main() {
4 traccia::set_hook(Hook::AfterLog(Box::new(|_, target| {
5 if let TargetId::Console(_) = target {
6 println!("This will be printed after the log message");
7 }
8 })));
9
10 traccia::set_hook(Hook::BeforeLog(Box::new(|level, target| {
11 if let TargetId::File(_) = target {
12 if level == LogLevel::Info {
13 println!("This will be printed only before calling the info! macro on a file.")
14 }
15 }
16 })));
17
18 traccia::set_hook(Hook::BeforeLog(Box::new(|_, target| {
19 if let TargetId::Console(_) = target {
20 println!("This will be printed before the log message");
21 }
22 })));
23
24 traccia::init_with_config(traccia::Config {
25 level: LogLevel::Trace,
26 targets: vec![
27 Box::new(traccia::Console::new()),
28 Box::new(
29 traccia::File::new("./.logs/latest.log", traccia::FileMode::Truncate)
30 .expect("Failed to open file."),
31 ),
32 ],
33 ..Default::default()
34 });
35
36 info!("This is a test log message");
37 warn!("This is a test warning message");
38}