pub enum OutputChannel {
File(FileSettings),
Console,
Auto(FileSettings),
}Expand description
Output Types for Logger.
Variants§
File(FileSettings)
Store to files.
Console
Output to stdout.
Auto(FileSettings)
If dev mode -> stdout, If release -> file
Implementations§
Source§impl OutputChannel
impl OutputChannel
pub fn console() -> Self
pub fn auto() -> Self
Sourcepub fn file(
path: PathBuf,
capacity: usize,
file_size: FileSize,
filename: String,
file_extension: String,
) -> Self
pub fn file( path: PathBuf, capacity: usize, file_size: FileSize, filename: String, file_extension: String, ) -> Self
Examples found in repository?
examples/demo.rs (lines 15-21)
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}pub fn settings(&self) -> Option<&FileSettings>
Trait Implementations§
Source§impl Clone for OutputChannel
impl Clone for OutputChannel
Source§fn clone(&self) -> OutputChannel
fn clone(&self) -> OutputChannel
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 OutputChannel
impl Debug for OutputChannel
Auto Trait Implementations§
impl Freeze for OutputChannel
impl RefUnwindSafe for OutputChannel
impl Send for OutputChannel
impl Sync for OutputChannel
impl Unpin for OutputChannel
impl UnsafeUnpin for OutputChannel
impl UnwindSafe for OutputChannel
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