102 lines
2.6 KiB
Rust
102 lines
2.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>,
|
|
pub(crate) log_use_json: bool,
|
|
pub(crate) log_json_show_timestamp: bool,
|
|
pub(crate) log_json_show_level: bool,
|
|
pub(crate) log_json_show_message: bool,
|
|
pub(crate) log_json_show_additional_fields: bool,
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
pub fn log_use_json(mut self, i: bool) -> Self {
|
|
self.log_use_json = i;
|
|
self
|
|
}
|
|
|
|
pub fn log_json_show_timestamp(mut self, i: bool) -> Self {
|
|
self.log_json_show_timestamp = i;
|
|
self
|
|
}
|
|
|
|
pub fn log_json_show_level(mut self, i: bool) -> Self {
|
|
self.log_json_show_level = i;
|
|
self
|
|
}
|
|
|
|
pub fn log_json_show_message(mut self, i: bool) -> Self {
|
|
self.log_json_show_message = i;
|
|
self
|
|
}
|
|
|
|
pub fn log_json_show_additional_fields(mut self, i: bool) -> Self {
|
|
self.log_json_show_additional_fields = 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,
|
|
log_use_json: false,
|
|
log_json_show_timestamp: false,
|
|
log_json_show_level: false,
|
|
log_json_show_message: false,
|
|
log_json_show_additional_fields: false
|
|
}
|
|
}
|
|
}
|