mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 08:14:07 +00:00
feat: disable ansi if stdout is not terminal
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
//! Logging facilities with tracing
|
||||
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use time::UtcOffset;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::{fmt::time::OffsetTime, EnvFilter, FmtSubscriber};
|
||||
@@ -21,6 +23,13 @@ pub fn init_with_config(bin_name: &str, config: &LogConfig) {
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE: ansi is enabled by default.
|
||||
// Could be disabled by `NO_COLOR` environment variable.
|
||||
// https://no-color.org/
|
||||
if !std::io::stdout().is_terminal() {
|
||||
builder = builder.with_ansi(false);
|
||||
}
|
||||
|
||||
if debug_level >= 1 {
|
||||
builder = builder.with_target(true).with_thread_ids(true).with_thread_names(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user