lang_interpreter/terminal_io/
custom_logging.rs

1#[cfg(feature = "wasm")]
2#[doc(hidden)]
3pub mod wasm;
4
5use std::fmt::Debug;
6use crate::terminal_io::Level;
7
8/// This trait is used to abstract logging functionality
9///
10/// This trait is only available if the `custom-logging` feature is enabled
11pub trait Logger: Debug {
12    fn log(&mut self, lvl: Level, time_label: &str, text: &str, tag: &str);
13}
14
15/// This [Logger] prints to standard out
16///
17/// This struct is only available if the `custom-logging` feature is enabled
18#[derive(Debug)]
19pub struct DefaultLogger;
20
21impl DefaultLogger {
22    pub fn new() -> Self {
23        Self
24    }
25}
26
27impl Default for DefaultLogger {
28    fn default() -> Self {
29        Self::new()
30    }
31}
32
33impl Logger for DefaultLogger {
34    fn log(&mut self, lvl: Level, time_label: &str, text: &str, tag: &str) {
35        println!(
36            "[{}][{}][{}]: {}",
37            lvl.name(),
38            time_label,
39            tag,
40            text,
41        );
42    }
43}