From 56eee6908ed42b543bd117f78fa7b002a822dd6d Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Thu, 10 Oct 2024 21:07:36 +0200 Subject: [PATCH] server: Add a way to print raw logs If the variable LLDAP_RAW_LOG is set, the logs will be both formatted with tracing_forest and printed raw --- server/src/infra/logging.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/infra/logging.rs b/server/src/infra/logging.rs index a6a68f1..9bade14 100644 --- a/server/src/infra/logging.rs +++ b/server/src/infra/logging.rs @@ -3,6 +3,7 @@ use actix_web::{ dev::{ServiceRequest, ServiceResponse}, Error, }; +use std::env; use tracing::{debug, error, Span}; use tracing_actix_web::RootSpanBuilder; use tracing_subscriber::{filter::EnvFilter, layer::SubscriberExt, util::SubscriberInitExt}; @@ -42,10 +43,14 @@ pub fn init(config: &Configuration) -> anyhow::Result<()> { "sqlx=warn,reqwest=warn,info" }) }); - tracing_subscriber::registry() + let registry = tracing_subscriber::registry() .with(env_filter) - .with(tracing_forest::ForestLayer::default()) - .init(); + .with(tracing_forest::ForestLayer::default()); + if env::var("LLDAP_RAW_LOG").is_ok() { + registry.with(tracing_subscriber::fmt::layer()).init(); + } else { + registry.init(); + } Ok(()) }