feat: event based non-blocking logger
This commit is contained in:
parent
28395167f0
commit
fff9c1562c
8 changed files with 534 additions and 671 deletions
58
subcrates/zlog/src/config.rs
Normal file
58
subcrates/zlog/src/config.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use crate::LogLevel;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[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
|
||||
}
|
||||
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: 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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue