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

66 lines
1.5 KiB
Rust
Raw Normal View History

2025-04-15 20:08:58 +00:00
use std::path::{Path, PathBuf};
2025-04-16 01:24:10 +00:00
use crate::LogLevel;
2025-04-15 20:08:58 +00:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LoggerConfig {
pub(crate) log_level: 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,
}
impl LoggerConfig {
pub fn level(mut self, level: LogLevel) -> Self {
self.log_level = level;
self
}
2025-04-16 01:24:10 +00:00
2025-04-15 20:08:58 +00:00
pub fn log_to_file(mut self, f: bool) -> Self {
self.log_to_file = f;
self
}
2025-04-16 01:24:10 +00:00
2025-04-15 20:08:58 +00:00
pub fn colored_stdout(mut self, c: bool) -> Self {
self.stdout_color = c;
self
}
2025-04-16 01:24:10 +00:00
2025-04-15 20:08:58 +00:00
pub fn log_to_stdout(mut self, s: bool) -> Self {
self.log_to_stdout = s;
self
}
2025-04-16 01:24:10 +00:00
2025-04-15 20:08:58 +00:00
pub fn log_path<P: AsRef<Path>>(mut self, p: P) -> Self {
self.log_file_path = p.as_ref().to_path_buf();
self
}
2025-04-16 01:24:10 +00:00
2025-04-15 20:08:58 +00:00
pub fn stdout_include_time(mut self, i: bool) -> Self {
self.stdout_include_time = i;
self
}
2025-04-16 01:24:10 +00:00
2025-04-15 20:08:58 +00:00
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: LogLevel::Debug,
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,
}
}
}