From 46ec3a469b995b8cce78730042fe590b75c04ad4 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Mon, 12 Jan 2026 00:18:23 +0000 Subject: [PATCH] fix: logging errors in deltachat-rpc-server during startup (#7707) Before this PR there were cases where error messages never reach the user because logging was not initialized yet. This PR moves log initialization to the start of the program, so that all logged messages reach the user. --- deltachat-rpc-server/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deltachat-rpc-server/src/main.rs b/deltachat-rpc-server/src/main.rs index 1e2adb5e6..2db7f0535 100644 --- a/deltachat-rpc-server/src/main.rs +++ b/deltachat-rpc-server/src/main.rs @@ -24,6 +24,14 @@ use yerpc::{RpcClient, RpcSession}; #[tokio::main(flavor = "multi_thread")] async fn main() { + // Logs from `log` crate and traces from `tracing` crate + // are configurable with `RUST_LOG` environment variable + // and go to stderr to avoid interfering with JSON-RPC using stdout. + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .with_writer(std::io::stderr) + .init(); + let r = main_impl().await; // From tokio documentation: // "For technical reasons, stdin is implemented by using an ordinary blocking read on a separate @@ -64,14 +72,6 @@ async fn main_impl() -> Result<()> { #[cfg(target_family = "unix")] let mut sigterm = signal_unix::signal(signal_unix::SignalKind::terminate())?; - // Logs from `log` crate and traces from `tracing` crate - // are configurable with `RUST_LOG` environment variable - // and go to stderr to avoid interfering with JSON-RPC using stdout. - tracing_subscriber::fmt() - .with_env_filter(EnvFilter::from_default_env()) - .with_writer(std::io::stderr) - .init(); - let path = std::env::var("DC_ACCOUNTS_PATH").unwrap_or_else(|_| "accounts".to_string()); log::info!("Starting with accounts directory `{path}`."); let writable = true;