use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum LogFormat {
Text,
Json,
}
impl Default for LogFormat {
fn default() -> Self {
Self::Text
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum LogStream {
Stderr,
Stdout,
}
impl Default for LogStream {
fn default() -> Self {
Self::Stderr
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LogConfig {
pub level: String,
pub format: LogFormat,
pub use_colors: Option<bool>,
pub compact_context: bool,
pub stream: LogStream,
}
impl Default for LogConfig {
fn default() -> Self {
Self {
level: "info".to_string(),
format: LogFormat::Text,
use_colors: None,
compact_context: true,
stream: LogStream::Stderr,
}
}
}
impl LogConfig {
pub fn from_app_fields(
level: &str,
format: LogFormat,
use_colors: Option<bool>,
compact_context: bool,
) -> Self {
Self {
level: level.to_owned(),
format,
use_colors,
compact_context,
stream: LogStream::Stderr,
}
}
}