Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
Simon-Laux committed Nov 16, 2025
commit 76eb2e4d3335c4bda33112eb6467441a07258f5b
5 changes: 3 additions & 2 deletions src/events/chatlist_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"
))),
),
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/log/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ impl<S: SessionStream> AsyncRead for LoggingStream<S> {
"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),
Expand Down
5 changes: 3 additions & 2 deletions src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,10 @@ pub(crate) async fn login_param_from_account_qr(
match serde_json::from_str::<CreateAccountErrorResponse>(&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:?}")
}
}
Expand Down
Loading