Skip to main content

MessageFormatter

Struct MessageFormatter 

Source
pub struct MessageFormatter { /* private fields */ }
Expand description

Formatted for Log Message.

Implementations§

Source§

impl MessageFormatter

Source

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}
Source

pub fn format(&self, message: &Message) -> String

Process input message with rules.

Trait Implementations§

Source§

impl Clone for MessageFormatter

Source§

fn clone(&self) -> MessageFormatter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageFormatter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MessageFormatter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.