mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-24 22:19:37 -04:00
try to use tracing but fucking fail
This commit is contained in:
parent
eda862ff1a
commit
fdd7d305b9
1 changed files with 52 additions and 12 deletions
|
@ -3,8 +3,10 @@ use std::path::Path;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing_subscriber::filter::LevelFilter;
|
use tracing_subscriber::filter::LevelFilter;
|
||||||
use tracing_subscriber::fmt::time::UtcTime;
|
use tracing_subscriber::fmt::time::UtcTime;
|
||||||
use tracing_subscriber::fmt::writer::MakeWriterExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::FmtSubscriber;
|
use tracing_subscriber::fmt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
level: LevelFilter,
|
level: LevelFilter,
|
||||||
|
@ -18,21 +20,59 @@ pub fn init(
|
||||||
|
|
||||||
let is_terminal = atty::is(atty::Stream::Stderr);
|
let is_terminal = atty::is(atty::Stream::Stderr);
|
||||||
|
|
||||||
let appender = tracing_appender::rolling::never(dir.as_ref(), "swap-all.log");
|
// File logger will always write in JSON format and with timestamps
|
||||||
|
let file_appender = tracing_appender::rolling::never(dir.as_ref(), "swap-all.log");
|
||||||
|
|
||||||
let builder = FmtSubscriber::builder()
|
let file_layer = fmt::layer()
|
||||||
.with_env_filter(format!("asb={},swap={}", level, level))
|
.with_writer(std::io::stdout)
|
||||||
.with_writer(appender.and(std::io::stderr))
|
.with_ansi(false)
|
||||||
|
.with_timer(UtcTime::rfc_3339())
|
||||||
|
.with_target(false)
|
||||||
|
.json();
|
||||||
|
|
||||||
|
// Terminal logger
|
||||||
|
let terminal_layer_base = fmt::layer()
|
||||||
|
.with_writer(std::io::stdout)
|
||||||
.with_ansi(is_terminal)
|
.with_ansi(is_terminal)
|
||||||
.with_timer(UtcTime::rfc_3339())
|
.with_timer(UtcTime::rfc_3339())
|
||||||
.with_target(false);
|
.with_target(false);
|
||||||
|
|
||||||
match (json_format, timestamp) {
|
// Since tracing is stupid, and makes each option return a different type
|
||||||
(true, true) => builder.json().init(),
|
// but also doesn't allow dynamic dispatch we have to use this beauty
|
||||||
(true, false) => builder.json().without_time().init(),
|
let (
|
||||||
(false, true) => builder.init(),
|
a,
|
||||||
(false, false) => builder.without_time().init(),
|
b,
|
||||||
}
|
c,
|
||||||
|
d
|
||||||
|
) = match (json_format, timestamp) {
|
||||||
|
(true, true) => (Some(terminal_layer_base.json()), None, None, None),
|
||||||
|
(true, false) => (None, Some(terminal_layer_base.json().without_time()), None, None),
|
||||||
|
(false, true) => (None, None, Some(terminal_layer_base), None),
|
||||||
|
(false, false) => (None, None, None, Some(terminal_layer_base.without_time())),
|
||||||
|
};
|
||||||
|
|
||||||
|
let combined_subscriber = tracing_subscriber::registry()
|
||||||
|
.with(file_layer)
|
||||||
|
.with(a);
|
||||||
|
|
||||||
|
combined_subscriber.init();
|
||||||
|
|
||||||
|
// let builder = FmtSubscriber::builder()
|
||||||
|
// .with_env_filter(format!("asb={},swap={}", level, level))
|
||||||
|
// .with_writer(async_file_appender.and(std::io::stderr))
|
||||||
|
// .with_ansi(is_terminal)
|
||||||
|
// .with_timer(UtcTime::rfc_3339())
|
||||||
|
// .with_target(false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// match (json_format, timestamp) {
|
||||||
|
// (true, true) => builder.json().init(),
|
||||||
|
// (true, false) => builder.json().without_time().init(),
|
||||||
|
// (false, true) => builder.init(),
|
||||||
|
// (false, false) => builder.without_time().init(),
|
||||||
|
// }
|
||||||
|
|
||||||
tracing::info!(%level, "Initialized tracing");
|
tracing::info!(%level, "Initialized tracing");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue