pub struct MessageFormatter { /* private fields */ }Expand description
Formatted for Log Message.
Implementations§
Source§impl MessageFormatter
impl MessageFormatter
Sourcepub fn new(splitter: &str, format: &str, timestamp: &str) -> Self
pub fn new(splitter: &str, format: &str, timestamp: &str) -> Self
Examples found in repository?
examples/demo.rs (lines 9-13)
8fn main() {
9 let formatter = MessageFormatter::new(
10 "::",
11 "{timestamp:-6:30:right}{splitter}{modules:_:_:left}{splitter}{message}",
12 "%Y-%m-%d %H:%M:%S.%f",
13 );
14
15 let output = OutputChannel::file(
16 "./logs".into(),
17 10,
18 FileSize::from_kilobytes(1),
19 "new_logger".into(),
20 "log".into(),
21 );
22
23 let settings = Settings::new(true, 5, output, formatter);
24
25 let logger = Logger::new(settings);
26 let joiner = logger.run_async();
27
28 let logger_logger_01 = logger.clone();
29 let logger_logger_02 = logger.clone();
30 let _ = thread::spawn(move || {
31 logger_logger_01.log(&vec!["THREAD1".into(), "MAIN".into()], "Starting...");
32
33 let mut counter = 0;
34 loop {
35 logger_logger_01.log(
36 &vec!["THREAD1".into(), "WORKER".into()],
37 format!("Processing Job: {counter}").as_str(),
38 );
39 counter += 1;
40 sleep(Duration::from_secs(1));
41 }
42 });
43
44 let _ = thread::spawn(move || {
45 logger_logger_02.log(&vec!["THREAD2".into(), "MAIN".into()], "Starting...");
46
47 let mut counter = 0;
48 loop {
49 logger_logger_02.log(
50 &vec!["THREAD2".into(), "WORKER".into()],
51 format!("Processing Job: {counter}").as_str(),
52 );
53 counter += 2;
54 sleep(Duration::from_millis(400));
55 }
56 });
57
58 let _ = thread::spawn(move || {
59 log!("Starting...");
60
61 let mut counter = 0;
62 loop {
63 log!(format!("Try Process Job: {counter}").as_str());
64
65 // Log as text
66 log!(
67 ["THREAD3", "MODULE1"],
68 format!("Try Process Job: {counter}").as_str()
69 );
70 let module_str = "RAW_MODULE";
71 let thread3_str = "THREAD3";
72
73 // Log from vars
74 log!(
75 [thread3_str, module_str],
76 format!("Try Process Job: {counter}").as_str()
77 );
78
79 // Log as ident
80 log!((RAW_MODULE, RAW_MODULE2, RAW_MODULE3), "some");
81 counter += 2;
82 sleep(Duration::from_millis(400));
83 }
84 });
85
86 match joiner {
87 Some(j) => {
88 let _ = j.join();
89 }
90 None => {}
91 };
92}Trait Implementations§
Source§impl Clone for MessageFormatter
impl Clone for MessageFormatter
Source§fn clone(&self) -> MessageFormatter
fn clone(&self) -> MessageFormatter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MessageFormatter
impl Debug for MessageFormatter
Auto Trait Implementations§
impl Freeze for MessageFormatter
impl RefUnwindSafe for MessageFormatter
impl Send for MessageFormatter
impl Sync for MessageFormatter
impl Unpin for MessageFormatter
impl UnsafeUnpin for MessageFormatter
impl UnwindSafe for MessageFormatter
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