Repository: jdrouet/catapulte (language: rust)

Issue:
add an environment variable to disable logging in color



Discussion / hints:

Fix patch:
diff --git a/Dockerfile b/Dockerfile
index d8bfdba2..518575ad 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -60,6 +60,7 @@ ENV HOST=0.0.0.0
 ENV PORT=3000
 ENV RUST_LOG=info
 ENV TEMPLATE_ROOT=/templates
+ENV DISABLE_LOG_COLOR=true
 
 COPY --from=builder /code/target/release/catapulte /usr/bin/catapulte
 
diff --git a/alpine.Dockerfile b/alpine.Dockerfile
index 23ccd65e..c9e5b214 100644
--- a/alpine.Dockerfile
+++ b/alpine.Dockerfile
@@ -56,6 +56,7 @@ ENV HOST=0.0.0.0
 ENV PORT=3000
 ENV RUST_LOG=info
 ENV TEMPLATE_ROOT=/templates
+ENV DISABLE_LOG_COLOR=true
 
 COPY --from=builder /code/target/release/catapulte /usr/bin/catapulte
 
diff --git a/src/main.rs b/src/main.rs
index da335b7d..bbf556a6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,16 +7,16 @@ mod controller;
 mod error;
 mod service;
 
-pub(crate) fn init_logs(directive: &str) {
+pub(crate) fn init_logs(directive: &str, color: bool) {
     tracing_subscriber::registry()
         .with(tracing_subscriber::EnvFilter::new(directive))
-        .with(tracing_subscriber::fmt::layer())
+        .with(tracing_subscriber::fmt::layer().with_ansi(color))
         .init();
 }
 
 #[cfg(test)]
 pub(crate) fn try_init_logs() {
-    let level = std::env::var("LOG").unwrap_or_else(|_| "catapulte=debug".into());
+    let level = std::env::var("LOG").unwrap_or_else(|_| "catapulte=debug,tower_http=debug".into());
     let _ = tracing_subscriber::registry()
         .with(tracing_subscriber::EnvFilter::new(level))
         .with(tracing_subscriber::fmt::layer())
@@ -27,15 +27,18 @@ pub(crate) fn try_init_logs() {
 #[clap(about, author, version)]
 struct Arguments {
     /// Log level.
-    #[clap(short, long, env, default_value = "INFO")]
+    #[clap(short, long, env, default_value = "catapulte=debug,tower_http=debug")]
     pub log: String,
+    /// Disable color in logs.
+    #[clap(long, env, default_value = "false")]
+    pub disable_log_color: bool,
     #[command(subcommand)]
     pub action: action::Action,
 }
 
 impl Arguments {
     fn init_logs(&self) {
-        init_logs(&self.log)
+        init_logs(&self.log, !self.disable_log_color)
     }
 }
 


Test patch: