1use core::time::Duration;
6use ringlog::*;
7
8macro_rules! command {
9 ($($arg:tt)*) => (
10 error!(target: "command", $($arg)*);
13 )
14}
15
16macro_rules! noplog {
17 ($($arg:tt)*) => (
18 error!(target: "noplog", $($arg)*);
21 )
22}
23
24fn main() {
25 let default = LogBuilder::new()
26 .output(Box::new(Stdout::new()))
27 .build()
28 .expect("failed to initialize default log");
29
30 let command = LogBuilder::new()
31 .output(Box::new(
32 File::new("command.log", "command.old", 100).expect("failed to create file log"),
33 ))
34 .format(klog_format)
35 .build()
36 .expect("failed to initialize command log");
37
38 let noplog = NopLogBuilder::new().build();
39
40 let mut drain = MultiLogBuilder::new()
41 .default(default)
42 .add_target("command", command)
43 .add_target("noplog", noplog)
44 .build()
45 .start();
46
47 std::thread::spawn(move || loop {
48 let _ = drain.flush();
49 std::thread::sleep(Duration::from_millis(100));
50 });
51
52 error!("error");
53 warn!("warning");
54 info!("info");
55 debug!("debug");
56 trace!("trace");
57
58 command!("\"get 0\" 0 0");
59
60 noplog!("this won't get displayed");
61
62 std::thread::sleep(Duration::from_millis(1000));
63}