zenyx-engine/subcrates/zlog/src/config.rs

67 lines
1.6 KiB
Rust

use std::path::{Path, PathBuf};
use crate::LogLevel;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LoggerConfig {
pub(crate) log_level: Option<LogLevel>,
pub(crate) log_to_file: bool,
pub(crate) log_file_path: PathBuf,
pub(crate) log_to_stdout: bool,
pub(crate) stdout_color: bool,
pub(crate) stdout_include_time: bool,
pub(crate) file_include_time: bool,
pub(crate) crate_max_level: Option<LogLevel>,
}
impl LoggerConfig {
pub fn level(mut self, level: LogLevel) -> Self {
self.log_level = Some(level);
self
}
pub fn log_to_file(mut self, f: bool) -> Self {
self.log_to_file = f;
self
}
pub fn colored_stdout(mut self, c: bool) -> Self {
self.stdout_color = c;
self
}
pub fn log_to_stdout(mut self, s: bool) -> Self {
self.log_to_stdout = s;
self
}
pub fn log_path<P: AsRef<Path>>(mut self, p: P) -> Self {
self.log_file_path = p.as_ref().to_path_buf();
self
}
pub fn stdout_include_time(mut self, i: bool) -> Self {
self.stdout_include_time = i;
self
}
pub fn file_include_time(mut self, i: bool) -> Self {
self.file_include_time = i;
self
}
}
impl Default for LoggerConfig {
fn default() -> Self {
Self {
log_level: None,
crate_max_level: None,
log_to_file: true,
log_file_path: "app.log".into(),
log_to_stdout: true,
stdout_color: true,
stdout_include_time: false,
file_include_time: false,
}
}
}