mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-04 20:44:33 -04:00
fix: change logs to UTC due to bug in time crate
On Linux and macOS, no program output was being observed. This is referenced in the [LocalTime] docs for `tracing-subscriber`, which links to this [unsoundness issue] in the time crate. Rather than introducing a possible vector for undefined behaviour and segfaults, I have just changed the logging to use UTC time instead. When running the ASB as a systemd service, one would generally use the `--disable-timestamps` flag anyway as systemd adds its own timestamps which can be local to the server. If the situation with `tracing-subscriber` and the time crate is fixed then this can be updated. This commit also updates the `tracing-subscriber` and `tracing-appender` dependencies, closing #987. [LocalTime]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html [unsoundness issue]: https://github.com/time-rs/time/issues/293#issuecomment-748151025
This commit is contained in:
parent
7023e75bb5
commit
8eff499a63
7 changed files with 62 additions and 32 deletions
|
@ -1,6 +1,6 @@
|
|||
use anyhow::Result;
|
||||
use tracing_subscriber::filter::LevelFilter;
|
||||
use tracing_subscriber::fmt::time::ChronoLocal;
|
||||
use tracing_subscriber::fmt::time::UtcTime;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
pub fn init(level: LevelFilter, json_format: bool, timestamp: bool) -> Result<()> {
|
||||
|
@ -14,7 +14,7 @@ pub fn init(level: LevelFilter, json_format: bool, timestamp: bool) -> Result<()
|
|||
.with_env_filter(format!("asb={},swap={}", level, level))
|
||||
.with_writer(std::io::stderr)
|
||||
.with_ansi(is_terminal)
|
||||
.with_timer(ChronoLocal::with_format("%F %T".to_owned()))
|
||||
.with_timer(UtcTime::rfc_3339())
|
||||
.with_target(false);
|
||||
|
||||
match (json_format, timestamp) {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use anyhow::Result;
|
||||
use std::option::Option::Some;
|
||||
use std::path::Path;
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
use tracing::subscriber::set_global_default;
|
||||
use tracing::{Event, Level, Subscriber};
|
||||
use tracing_subscriber::fmt::format::{DefaultFields, Format, JsonFields};
|
||||
use tracing_subscriber::fmt::time::ChronoLocal;
|
||||
use tracing_subscriber::fmt::time::UtcTime;
|
||||
use tracing_subscriber::layer::{Context, SubscriberExt};
|
||||
use tracing_subscriber::{fmt, EnvFilter, FmtSubscriber, Layer, Registry};
|
||||
use uuid::Uuid;
|
||||
|
@ -47,7 +48,7 @@ pub fn init(debug: bool, json: bool, dir: impl AsRef<Path>, swap_id: Option<Uuid
|
|||
.with_env_filter(format!("swap={}", level))
|
||||
.with_writer(std::io::stderr)
|
||||
.with_ansi(is_terminal)
|
||||
.with_timer(ChronoLocal::with_format("%F %T".to_owned()))
|
||||
.with_timer(UtcTime::rfc_3339())
|
||||
.with_target(false);
|
||||
|
||||
if json {
|
||||
|
@ -79,25 +80,25 @@ type StdErrJsonLayer<S, T> = tracing_subscriber::fmt::Layer<
|
|||
fn() -> std::io::Stderr,
|
||||
>;
|
||||
|
||||
fn debug_terminal_printer<S>() -> StdErrPrinter<StdErrLayer<S, ChronoLocal>> {
|
||||
fn debug_terminal_printer<S>() -> StdErrPrinter<StdErrLayer<S, UtcTime<Rfc3339>>> {
|
||||
let is_terminal = atty::is(atty::Stream::Stderr);
|
||||
StdErrPrinter {
|
||||
inner: fmt::layer()
|
||||
.with_ansi(is_terminal)
|
||||
.with_target(false)
|
||||
.with_timer(ChronoLocal::with_format("%F %T".to_owned()))
|
||||
.with_timer(UtcTime::rfc_3339())
|
||||
.with_writer(std::io::stderr),
|
||||
level: Level::DEBUG,
|
||||
}
|
||||
}
|
||||
|
||||
fn debug_json_terminal_printer<S>() -> StdErrPrinter<StdErrJsonLayer<S, ChronoLocal>> {
|
||||
fn debug_json_terminal_printer<S>() -> StdErrPrinter<StdErrJsonLayer<S, UtcTime<Rfc3339>>> {
|
||||
let is_terminal = atty::is(atty::Stream::Stderr);
|
||||
StdErrPrinter {
|
||||
inner: fmt::layer()
|
||||
.with_ansi(is_terminal)
|
||||
.with_target(false)
|
||||
.with_timer(ChronoLocal::with_format("%F %T".to_owned()))
|
||||
.with_timer(UtcTime::rfc_3339())
|
||||
.json()
|
||||
.with_writer(std::io::stderr),
|
||||
level: Level::DEBUG,
|
||||
|
|
|
@ -41,7 +41,7 @@ impl MakeCapturingWriter {
|
|||
}
|
||||
}
|
||||
|
||||
impl MakeWriter for MakeCapturingWriter {
|
||||
impl<'a> MakeWriter<'a> for MakeCapturingWriter {
|
||||
type Writer = CapturingWriter;
|
||||
|
||||
fn make_writer(&self) -> Self::Writer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue