From f6050ecae9123b8eb415d87dc94a56533a00d0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 26 Aug 2026 12:28:18 +0200 Subject: [PATCH] Log to a file when not launched from a terminal --- crates/radicle-tauri/src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/radicle-tauri/src/lib.rs b/crates/radicle-tauri/src/lib.rs index d58d5e202..7e7e70d1d 100644 --- a/crates/radicle-tauri/src/lib.rs +++ b/crates/radicle-tauri/src/lib.rs @@ -1,6 +1,7 @@ mod commands; use radicle_types::AppState; +use tauri_plugin_log::{Target, TargetKind}; use commands::{auth, cob, diff, inbox, profile, repo, startup, thread}; @@ -16,14 +17,23 @@ pub fn run() { log::warn!("Unable to set open file limit: {e}"); } - #[cfg(debug_assertions)] + // Launched from the desktop there is nowhere for stdout to go, so the logs + // belong in a file instead. `TERM` is what tells the two cases apart: it + // survives the pipes that `npm run tauri dev` puts between the app and the + // terminal, which `std::io::IsTerminal` on our own stdout would not. + let terminal = std::env::var_os("TERM").is_some(); let builder = tauri::Builder::default().plugin( tauri_plugin_log::Builder::new() .level(log::LevelFilter::Info) + .max_file_size(5_000_000) + .rotation_strategy(tauri_plugin_log::RotationStrategy::KeepOne) + .target(Target::new(if terminal { + TargetKind::Stdout + } else { + TargetKind::LogDir { file_name: None } + })) .build(), ); - #[cfg(not(debug_assertions))] - let builder = tauri::Builder::default(); builder .plugin(tauri_plugin_dialog::init())