mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 05:45:40 +00:00
66db8e1851
By updating `tracing_log`, we can access the re-export. That we need to initialize the `tracing_log` adaptor. The usage of `log::LevelFilter` for the `init_tracing` function was conceptually incorrect. We should be using a type from the `tracing` library here.
30 lines
893 B
Rust
30 lines
893 B
Rust
use anyhow::Result;
|
|
use atty::{self};
|
|
use tracing::{info, subscriber};
|
|
use tracing_log::LogTracer;
|
|
use tracing_subscriber::{filter::LevelFilter, FmtSubscriber};
|
|
|
|
pub fn init_tracing(level: LevelFilter) -> Result<()> {
|
|
if level == LevelFilter::OFF {
|
|
return Ok(());
|
|
}
|
|
|
|
// We want upstream library log messages, just only at Info level.
|
|
LogTracer::init_with_filter(tracing_log::log::LevelFilter::Info)?;
|
|
|
|
let is_terminal = atty::is(atty::Stream::Stderr);
|
|
let subscriber = FmtSubscriber::builder()
|
|
.with_env_filter(format!(
|
|
"swap={},monero_harness={},bitcoin_harness={},http=warn,warp=warn",
|
|
level, level, level,
|
|
))
|
|
.with_writer(std::io::stderr)
|
|
.with_ansi(is_terminal)
|
|
.finish();
|
|
|
|
subscriber::set_global_default(subscriber)?;
|
|
info!("Initialized tracing with level: {}", level);
|
|
|
|
Ok(())
|
|
}
|