From 76eb2e4d3335c4bda33112eb6467441a07258f5b Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Sun, 16 Nov 2025 23:08:40 +0100 Subject: [PATCH 1/3] fix: use logging macros instead of emitting event directly, so that it is also logged by tracing The events are needed when you are not using chatmail core from rust, if you use chatmail core from your rust bot or from tauri, then you likely already use the rust logging/tracing ecosystem. So it makes sense to use it instead of listening to the events and logging them yourself. This pr fixes a few cases where the event was direclty emitted instead of using the macro and thus was not also automatically logged via tracing. --- src/events/chatlist_events.rs | 5 +++-- src/log/stream.rs | 5 +++++ src/qr.rs | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/events/chatlist_events.rs b/src/events/chatlist_events.rs index 93ea7b6803..50ee068283 100644 --- a/src/events/chatlist_events.rs +++ b/src/events/chatlist_events.rs @@ -30,9 +30,10 @@ pub(crate) async fn emit_chatlist_item_changed_for_contact_chat( match ChatId::lookup_by_contact(context, contact_id).await { Ok(Some(chat_id)) => self::emit_chatlist_item_changed(context, chat_id), Ok(None) => {} - Err(error) => context.emit_event(EventType::Error(format!( + Err(error) => error!( + context, "failed to find chat id for contact for chatlist event: {error:?}" - ))), + ), } } diff --git a/src/log/stream.rs b/src/log/stream.rs index 00b7955dcf..daeabf05cd 100644 --- a/src/log/stream.rs +++ b/src/log/stream.rs @@ -91,6 +91,11 @@ impl AsyncRead for LoggingStream { "Read error on stream {peer_addr:?} after reading {} and writing {} bytes: {err}.", this.metrics.total_read, this.metrics.total_written ); + tracing::event!( + ::tracing::Level::WARN, + account_id = *this.account_id, + log_message + ); this.events.emit(Event { id: *this.account_id, typ: EventType::Warning(log_message), diff --git a/src/qr.rs b/src/qr.rs index 61816b76ca..98797c3ec9 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -748,9 +748,10 @@ pub(crate) async fn login_param_from_account_qr( match serde_json::from_str::(&response_text) { Ok(error) => Err(anyhow!(error.reason)), Err(parse_error) => { - context.emit_event(EventType::Error(format!( + error!( + context, "Cannot create account, server response could not be parsed:\n{parse_error:#}\nraw response:\n{response_text}" - ))); + ); bail!("Cannot create account, unexpected server response:\n{response_text:?}") } } From 06e6dc8eb9f18dac54a498ace58b858f397c80b4 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Sun, 16 Nov 2025 23:27:41 +0100 Subject: [PATCH 2/3] also emit tracing events on account events in methods that doen't use the macro, because they can't capture self. --- src/accounts.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/accounts.rs b/src/accounts.rs index eaa6563845..fa9995a1f9 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -360,6 +360,11 @@ impl Accounts { "Starting background fetch for {n_accounts} accounts." )), }); + ::tracing::event!( + ::tracing::Level::INFO, + account_id = 0, + "Starting background fetch for {n_accounts} accounts." + ); let mut set = JoinSet::new(); for account in accounts { set.spawn(async move { @@ -375,6 +380,11 @@ impl Accounts { "Finished background fetch for {n_accounts} accounts." )), }); + ::tracing::event!( + ::tracing::Level::INFO, + account_id = 0, + "Finished background fetch for {n_accounts} accounts." + ); } /// Auxiliary function for [Accounts::background_fetch]. @@ -393,6 +403,11 @@ impl Accounts { id: 0, typ: EventType::Warning("Background fetch timed out.".to_string()), }); + ::tracing::event!( + ::tracing::Level::WARN, + account_id = 0, + "Background fetch timed out." + ); } events.emit(Event { id: 0, From 253b2b127e74cf9ea01d8a5c4cd479f448e225ec Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Sun, 16 Nov 2025 23:28:33 +0100 Subject: [PATCH 3/3] rm unused import --- src/qr.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qr.rs b/src/qr.rs index 98797c3ec9..8c82332f7a 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -16,7 +16,6 @@ use serde::Deserialize; use crate::config::Config; use crate::contact::{Contact, ContactId, Origin}; use crate::context::Context; -use crate::events::EventType; use crate::key::Fingerprint; use crate::login_param::{EnteredCertificateChecks, EnteredLoginParam, EnteredServerLoginParam}; use crate::net::http::post_empty;