diff --git a/Cargo.lock b/Cargo.lock index 5ef4004469..b8a4e670d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1367,6 +1367,7 @@ dependencies = [ "tokio-tar", "tokio-util", "toml", + "tracing", "url", "uuid", "webpki-roots", diff --git a/Cargo.toml b/Cargo.toml index 4dd48fbafd..ce5f466090 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,6 +108,7 @@ tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar tokio-util = { workspace = true } tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] } toml = "0.8" +tracing = "0.1.41" url = "2" uuid = { version = "1", features = ["serde", "v4"] } webpki-roots = "0.26.8" diff --git a/src/accounts.rs b/src/accounts.rs index 13f61422a5..ad3266e28d 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -53,6 +53,14 @@ impl Accounts { Accounts::open(dir, writable).await } + /// Get the ID used to log events. + /// + /// Account manager logs events with ID 0 + /// which is not used by any accounts. + fn get_id(&self) -> u32 { + 0 + } + /// Creates a new default structure. async fn create(dir: &Path) -> Result<()> { fs::create_dir_all(dir) diff --git a/src/log.rs b/src/log.rs index ab6b154948..b4edc82a3a 100644 --- a/src/log.rs +++ b/src/log.rs @@ -14,6 +14,7 @@ macro_rules! info { file = file!(), line = line!(), msg = &formatted); + ::tracing::event!(::tracing::Level::INFO, account_id = $ctx.get_id(), "{}", &formatted); $ctx.emit_event($crate::EventType::Info(full)); }}; } @@ -33,6 +34,7 @@ mod warn_macro_mod { file = file!(), line = line!(), msg = &formatted); + ::tracing::event!(::tracing::Level::WARN, account_id = $ctx.get_id(), "{}", &formatted); $ctx.emit_event($crate::EventType::Warning(full)); }}; } @@ -48,6 +50,7 @@ macro_rules! error { }; ($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{ let formatted = format!($msg, $($args),*); + ::tracing::event!(::tracing::Level::ERROR, account_id = $ctx.get_id(), "{}", &formatted); $ctx.set_last_error(&formatted); $ctx.emit_event($crate::EventType::Error(formatted)); }}; @@ -113,6 +116,12 @@ impl LogExt for Result { ); // We can't use the warn!() macro here as the file!() and line!() macros // don't work with #[track_caller] + tracing::event!( + ::tracing::Level::WARN, + account_id = context.get_id(), + "{}", + &full + ); context.emit_event(crate::EventType::Warning(full)); }; self