use tracing_subscriber::EnvFilter;
pub fn init_logging() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.with_target(false)
.compact()
.try_init()
}
pub fn init_logging_json() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.json()
.try_init()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn init_logging_does_not_panic() {
let _ = init_logging();
}
#[test]
fn init_logging_json_does_not_panic() {
let _ = init_logging_json();
}
}