logger_rust/config/mod.rs
1pub use crate::log_rotator::LogRotatorConfig;
2
3use std::{
4 sync::Mutex,
5 path::PathBuf
6};
7
8lazy_static::lazy_static! {
9 pub static ref LOG_LEVEL: Mutex<LogLevel> = Mutex::new(LogLevel::Console);
10 pub static ref LOG_PATH: Mutex<PathBuf> = Mutex::new(PathBuf::new());
11 pub static ref LOG_MUTEX: Mutex<()> = Mutex::new(());
12 pub static ref LOG_ROTATOR_CONFIG: Mutex<Option<LogRotatorConfig>> = Mutex::new(None);
13}
14
15#[derive(Copy, Clone, PartialEq)]
16pub enum LogLevel {
17/// # LogLevel enum
18/// Defines the logger levels parameters: `Console`, `File`, `Both`
19/// - The `Console` level will output logs only into console buffer
20/// - The `File` level will place logs only into files, including existing logs
21/// - The `Both` level **does the both**.
22 Console,
23 File,
24 Both
25}
26
27pub trait LogVariables {
28/// Trait that defines a method for accessing the current log level.
29///
30/// This trait defines a `log_level` method that returns a reference to a `Mutex<LogLevel>`
31/// that contains the current log level. The log level determines where log messages are written:
32/// to the console, to a file, or both.
33/// `fn log_level(&self)` - Returns a reference to a `Mutex<LogLevel>` that contains the current log level.
34 fn log_level(&self) -> &Mutex<LogLevel>;
35}
36
37pub struct LogVariablesImpl;
38/// Implementation of the `LogVariables` trait for the `LogVariablesImpl` struct.
39impl LogVariables for LogVariablesImpl {
40/// Implementation of the `LogVariables` trait for the `LogVariablesImpl` struct.
41///
42/// This implementation provides a `log_level` method that returns a reference to the
43/// `LOG_LEVEL` static variable, which contains the current log level.
44///
45 fn log_level(&self) -> &Mutex<LogLevel> {
46//! Returns a reference to the `LOG_LEVEL` static variable, which contains the current
47//! log level.
48 &LOG_LEVEL
49 }
50}