use crab_vault::logger::LogLevel;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)]
pub struct LoggerConfig {
pub(super) level: LogLevel,
pub(super) with_ansi: bool,
pub(super) with_file: bool,
pub(super) with_target: bool,
pub(super) with_thread: bool,
pub(super) dump_path: Option<String>,
pub(super) dump_level: Option<LogLevel>,
}
impl Default for LoggerConfig {
fn default() -> Self {
Self {
level: LogLevel::Trace,
dump_path: None,
dump_level: None,
with_ansi: true,
with_file: true,
with_target: true,
with_thread: true,
}
}
}
impl LoggerConfig {
pub fn level(&self) -> LogLevel {
self.level
}
pub fn dump_path(&self) -> Option<&str> {
match &self.dump_path {
Some(val) => Some(val),
None => None,
}
}
pub fn dump_level(&self) -> Option<LogLevel> {
if self.dump_path().is_some() {
match self.dump_level {
Some(val) => Some(val),
None => Some(LogLevel::Warn),
}
} else {
None
}
}
pub fn with_ansi(&self) -> bool {
self.with_ansi
}
pub fn with_file(&self) -> bool {
self.with_file
}
pub fn with_target(&self) -> bool {
self.with_target
}
pub fn with_thread(&self) -> bool {
self.with_thread
}
}