mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Disable timestamp if we log to a non-interactive terminal
A non-interactive terminal is likely something along the lines of journalctl which captures a timestamp by itself. In theory, it could also be just a logfile but we rather accept this limitation and keep the configuration surface simple rather than exposing another config switch.
This commit is contained in:
parent
edb8851ce2
commit
9e3a104b42
@ -1,5 +1,4 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::{info, subscriber};
|
|
||||||
use tracing_log::LogTracer;
|
use tracing_log::LogTracer;
|
||||||
use tracing_subscriber::filter::LevelFilter;
|
use tracing_subscriber::filter::LevelFilter;
|
||||||
use tracing_subscriber::FmtSubscriber;
|
use tracing_subscriber::FmtSubscriber;
|
||||||
@ -13,14 +12,20 @@ pub fn init_tracing(level: LevelFilter) -> Result<()> {
|
|||||||
LogTracer::init_with_filter(tracing_log::log::LevelFilter::Info)?;
|
LogTracer::init_with_filter(tracing_log::log::LevelFilter::Info)?;
|
||||||
|
|
||||||
let is_terminal = atty::is(atty::Stream::Stderr);
|
let is_terminal = atty::is(atty::Stream::Stderr);
|
||||||
let subscriber = FmtSubscriber::builder()
|
|
||||||
.with_env_filter(format!("asb={},swap={}", level, level,))
|
let builder = FmtSubscriber::builder()
|
||||||
|
.with_env_filter(format!("asb={},swap={}", level, level))
|
||||||
.with_writer(std::io::stderr)
|
.with_writer(std::io::stderr)
|
||||||
.with_ansi(is_terminal)
|
.with_ansi(is_terminal)
|
||||||
.finish();
|
.with_target(false);
|
||||||
|
|
||||||
subscriber::set_global_default(subscriber)?;
|
if !is_terminal {
|
||||||
info!("Initialized tracing with level: {}", level);
|
builder.without_time().init();
|
||||||
|
} else {
|
||||||
|
builder.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::info!("Initialized tracing with level: {}", level);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user