xmr-btc-swap/swap/src/trace.rs
Thomas Eizinger 66db8e1851
Remove unnecessary log dependency
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.
2021-02-23 14:30:32 +11:00

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(())
}