mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
feat: log emitted logging events with tracing
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1367,6 +1367,7 @@ dependencies = [
|
|||||||
"tokio-tar",
|
"tokio-tar",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"toml",
|
"toml",
|
||||||
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar
|
|||||||
tokio-util = { workspace = true }
|
tokio-util = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
|
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
|
tracing = "0.1.41"
|
||||||
url = "2"
|
url = "2"
|
||||||
uuid = { version = "1", features = ["serde", "v4"] }
|
uuid = { version = "1", features = ["serde", "v4"] }
|
||||||
webpki-roots = "0.26.8"
|
webpki-roots = "0.26.8"
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ impl Accounts {
|
|||||||
Accounts::open(dir, writable).await
|
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.
|
/// Creates a new default structure.
|
||||||
async fn create(dir: &Path) -> Result<()> {
|
async fn create(dir: &Path) -> Result<()> {
|
||||||
fs::create_dir_all(dir)
|
fs::create_dir_all(dir)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ macro_rules! info {
|
|||||||
file = file!(),
|
file = file!(),
|
||||||
line = line!(),
|
line = line!(),
|
||||||
msg = &formatted);
|
msg = &formatted);
|
||||||
|
::tracing::event!(::tracing::Level::INFO, account_id = $ctx.get_id(), "{}", &formatted);
|
||||||
$ctx.emit_event($crate::EventType::Info(full));
|
$ctx.emit_event($crate::EventType::Info(full));
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@@ -33,6 +34,7 @@ mod warn_macro_mod {
|
|||||||
file = file!(),
|
file = file!(),
|
||||||
line = line!(),
|
line = line!(),
|
||||||
msg = &formatted);
|
msg = &formatted);
|
||||||
|
::tracing::event!(::tracing::Level::WARN, account_id = $ctx.get_id(), "{}", &formatted);
|
||||||
$ctx.emit_event($crate::EventType::Warning(full));
|
$ctx.emit_event($crate::EventType::Warning(full));
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@@ -48,6 +50,7 @@ macro_rules! error {
|
|||||||
};
|
};
|
||||||
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
||||||
let formatted = format!($msg, $($args),*);
|
let formatted = format!($msg, $($args),*);
|
||||||
|
::tracing::event!(::tracing::Level::ERROR, account_id = $ctx.get_id(), "{}", &formatted);
|
||||||
$ctx.set_last_error(&formatted);
|
$ctx.set_last_error(&formatted);
|
||||||
$ctx.emit_event($crate::EventType::Error(formatted));
|
$ctx.emit_event($crate::EventType::Error(formatted));
|
||||||
}};
|
}};
|
||||||
@@ -113,6 +116,12 @@ impl<T, E: std::fmt::Display> LogExt<T, E> for Result<T, E> {
|
|||||||
);
|
);
|
||||||
// We can't use the warn!() macro here as the file!() and line!() macros
|
// We can't use the warn!() macro here as the file!() and line!() macros
|
||||||
// don't work with #[track_caller]
|
// don't work with #[track_caller]
|
||||||
|
tracing::event!(
|
||||||
|
::tracing::Level::WARN,
|
||||||
|
account_id = context.get_id(),
|
||||||
|
"{}",
|
||||||
|
&full
|
||||||
|
);
|
||||||
context.emit_event(crate::EventType::Warning(full));
|
context.emit_event(crate::EventType::Warning(full));
|
||||||
};
|
};
|
||||||
self
|
self
|
||||||
|
|||||||
Reference in New Issue
Block a user