rs_zero/core/logging/
config.rs1use crate::core::logging::{redaction::RedactionConfig, writer::LogWriterConfig};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum LogFormat {
6 Text,
8 Json,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum LogSpanEvents {
15 None,
17 Close,
19 NewAndClose,
21 Full,
23}
24
25#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct LogConfig {
28 pub filter: String,
30 pub ansi: bool,
32 pub format: LogFormat,
34 pub with_target: bool,
36 pub include_current_span: bool,
38 pub include_span_list: bool,
40 pub span_events: LogSpanEvents,
42 pub service: Option<String>,
44 pub writer: LogWriterConfig,
46 pub redaction: RedactionConfig,
48}
49
50impl Default for LogConfig {
51 fn default() -> Self {
52 Self {
53 filter: "info".to_string(),
54 ansi: true,
55 format: LogFormat::Text,
56 with_target: true,
57 include_current_span: true,
58 include_span_list: false,
59 span_events: LogSpanEvents::Close,
60 service: None,
61 writer: LogWriterConfig::Stdout,
62 redaction: RedactionConfig::default(),
63 }
64 }
65}
66
67impl LogConfig {
68 pub fn from_env() -> Self {
70 Self {
71 filter: std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()),
72 ..Self::default()
73 }
74 }
75
76 pub fn with_format(mut self, format: LogFormat) -> Self {
78 self.format = format;
79 self
80 }
81
82 pub fn with_service(mut self, service: impl Into<String>) -> Self {
84 self.service = Some(service.into());
85 self
86 }
87
88 pub fn with_writer(mut self, writer: LogWriterConfig) -> Self {
90 self.writer = writer;
91 self
92 }
93
94 pub fn with_redaction(mut self, redaction: RedactionConfig) -> Self {
96 self.redaction = redaction;
97 self
98 }
99}