use crate::core::logging::{redaction::RedactionConfig, writer::LogWriterConfig};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogFormat {
Text,
Json,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogSpanEvents {
None,
Close,
NewAndClose,
Full,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LogConfig {
pub filter: String,
pub ansi: bool,
pub format: LogFormat,
pub with_target: bool,
pub include_current_span: bool,
pub include_span_list: bool,
pub span_events: LogSpanEvents,
pub service: Option<String>,
pub writer: LogWriterConfig,
pub redaction: RedactionConfig,
}
impl Default for LogConfig {
fn default() -> Self {
Self {
filter: "info".to_string(),
ansi: true,
format: LogFormat::Text,
with_target: true,
include_current_span: true,
include_span_list: false,
span_events: LogSpanEvents::Close,
service: None,
writer: LogWriterConfig::Stdout,
redaction: RedactionConfig::default(),
}
}
}
impl LogConfig {
pub fn from_env() -> Self {
Self {
filter: std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()),
..Self::default()
}
}
pub fn with_format(mut self, format: LogFormat) -> Self {
self.format = format;
self
}
pub fn with_service(mut self, service: impl Into<String>) -> Self {
self.service = Some(service.into());
self
}
pub fn with_writer(mut self, writer: LogWriterConfig) -> Self {
self.writer = writer;
self
}
pub fn with_redaction(mut self, redaction: RedactionConfig) -> Self {
self.redaction = redaction;
self
}
}