Log without colour codes when the output is not a terminal
Under systemd the log goes to the journal, where ANSI escape codes are noise. Colours are kept for a person at a terminal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b0c94f6643
commit
9820a5d3bc
1 file changed
+8
-1
@@ -1,5 +1,7 @@
|
|||||||
//! What the daemon logs, and how much.
|
//! What the daemon logs, and how much.
|
||||||
|
|
||||||
|
use std::io::IsTerminal;
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
@@ -23,7 +25,12 @@ impl LoggingArgs {
|
|||||||
let filter = EnvFilter::builder()
|
let filter = EnvFilter::builder()
|
||||||
.from_env_lossy()
|
.from_env_lossy()
|
||||||
.add_directive(format!("{OURS}={}", self.level).parse()?);
|
.add_directive(format!("{OURS}={}", self.level).parse()?);
|
||||||
tracing_subscriber::fmt().with_env_filter(filter).init();
|
// Colours for a person at a terminal; plain text for the journal
|
||||||
|
// or a file, where escape codes are noise.
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(filter)
|
||||||
|
.with_ansi(std::io::stdout().is_terminal())
|
||||||
|
.init();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user