Skip to content

Commit ba51bce

Browse files
committed
feat: log emitted logging events with tracing
1 parent c85e7b2 commit ba51bce

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar
108108
tokio-util = { workspace = true }
109109
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
110110
toml = "0.8"
111+
tracing = "0.1.41"
111112
url = "2"
112113
uuid = { version = "1", features = ["serde", "v4"] }
113114
webpki-roots = "0.26.8"

src/accounts.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ impl Accounts {
5353
Accounts::open(dir, writable).await
5454
}
5555

56+
/// Get the ID used to log events.
57+
///
58+
/// Account manager logs events with ID 0
59+
/// which is not used by any accounts.
60+
fn get_id(&self) -> u32 {
61+
0
62+
}
63+
5664
/// Creates a new default structure.
5765
async fn create(dir: &Path) -> Result<()> {
5866
fs::create_dir_all(dir)

src/log.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ macro_rules! info {
1414
file = file!(),
1515
line = line!(),
1616
msg = &formatted);
17+
::tracing::event!(::tracing::Level::INFO, account_id = $ctx.get_id(), "{}", &formatted);
1718
$ctx.emit_event($crate::EventType::Info(full));
1819
}};
1920
}
@@ -33,6 +34,7 @@ mod warn_macro_mod {
3334
file = file!(),
3435
line = line!(),
3536
msg = &formatted);
37+
::tracing::event!(::tracing::Level::WARN, account_id = $ctx.get_id(), "{}", &formatted);
3638
$ctx.emit_event($crate::EventType::Warning(full));
3739
}};
3840
}
@@ -48,6 +50,7 @@ macro_rules! error {
4850
};
4951
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
5052
let formatted = format!($msg, $($args),*);
53+
::tracing::event!(::tracing::Level::ERROR, account_id = $ctx.get_id(), "{}", &formatted);
5154
$ctx.set_last_error(&formatted);
5255
$ctx.emit_event($crate::EventType::Error(formatted));
5356
}};
@@ -103,6 +106,7 @@ impl<T, E: std::fmt::Display> LogExt<T, E> for Result<T, E> {
103106
);
104107
// We can't use the warn!() macro here as the file!() and line!() macros
105108
// don't work with #[track_caller]
109+
tracing::event!(::tracing::Level::WARN, account_id = context.get_id(), "{}", &full);
106110
context.emit_event(crate::EventType::Warning(full));
107111
};
108112
self

0 commit comments

Comments
 (0)