#[derive(Debug, Clone)]
pub struct JsonFormatterConfig {
pub include_timestamp: bool,
pub include_level: bool,
pub include_message: bool,
pub include_trace_id: bool,
pub include_span_id: bool,
pub include_target: bool,
pub include_file: bool,
pub include_line: bool,
}
impl Default for JsonFormatterConfig {
fn default() -> Self {
Self {
include_timestamp: true,
include_level: true,
include_message: true,
include_trace_id: true,
include_span_id: true,
include_target: true,
include_file: true,
include_line: true,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct JsonFormatter {
config: JsonFormatterConfig,
}
impl JsonFormatter {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(config: JsonFormatterConfig) -> Self {
Self { config }
}
pub fn include_timestamp(mut self, include: bool) -> Self {
self.config.include_timestamp = include;
self
}
pub fn include_level(mut self, include: bool) -> Self {
self.config.include_level = include;
self
}
pub fn include_message(mut self, include: bool) -> Self {
self.config.include_message = include;
self
}
pub fn include_trace_id(mut self, include: bool) -> Self {
self.config.include_trace_id = include;
self
}
pub fn include_span_id(mut self, include: bool) -> Self {
self.config.include_span_id = include;
self
}
pub fn include_target(mut self, include: bool) -> Self {
self.config.include_target = include;
self
}
pub fn include_file(mut self, include: bool) -> Self {
self.config.include_file = include;
self
}
pub fn include_line(mut self, include: bool) -> Self {
self.config.include_line = include;
self
}
}