diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 634c66f31..527cea6e9 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2068,6 +2068,7 @@ dependencies = [ "tokio", "tracing", "tracing-log 0.2.0", + "tracing-panic", "tracing-subscriber", "url", "uuid", @@ -6619,6 +6620,16 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-panic" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf80030ce049691c9922d75be63cadf345110a245cd4581833c66f87c02ad25" +dependencies = [ + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-serde" version = "0.1.3" diff --git a/rust/windows-client/src-tauri/Cargo.toml b/rust/windows-client/src-tauri/Cargo.toml index 9adb67cf6..619c72c07 100755 --- a/rust/windows-client/src-tauri/Cargo.toml +++ b/rust/windows-client/src-tauri/Cargo.toml @@ -34,6 +34,7 @@ tracing-log = "0.2" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } url = { version = "2.5.0", features = ["serde"] } uuid = { version = "1.5.0", features = ["v4"] } +tracing-panic = "0.1.1" zip = { version = "0.6.6", features = ["deflate", "time"], default-features = false } # These dependencies are locked behind `cfg(windows)` because they either can't compile at all on Linux, or they need native dependencies like glib that are difficult to get. Try not to add more here. diff --git a/rust/windows-client/src-tauri/src/client.rs b/rust/windows-client/src-tauri/src/client.rs index 2c0274041..831b975b0 100644 --- a/rust/windows-client/src-tauri/src/client.rs +++ b/rust/windows-client/src-tauri/src/client.rs @@ -32,6 +32,7 @@ pub(crate) struct AppLocalDataDir(std::path::PathBuf); const CREATE_NO_WINDOW: u32 = 0x08000000; pub(crate) fn run() -> Result<()> { + std::panic::set_hook(Box::new(tracing_panic::panic_hook)); let cli = cli::Cli::parse(); match cli.command { @@ -66,6 +67,7 @@ pub(crate) fn run() -> Result<()> { println!("debug"); Ok(()) } + Some(Cmd::DebugCrash) => debug_commands::crash(), Some(Cmd::DebugHostname) => debug_commands::hostname(), Some(Cmd::DebugPipeServer) => debug_commands::pipe_server(), Some(Cmd::DebugWintun) => debug_commands::wintun(cli), diff --git a/rust/windows-client/src-tauri/src/client/cli.rs b/rust/windows-client/src-tauri/src/client/cli.rs index 3591556fe..da6fb0d6e 100755 --- a/rust/windows-client/src-tauri/src/client/cli.rs +++ b/rust/windows-client/src-tauri/src/client/cli.rs @@ -12,6 +12,7 @@ pub struct Cli { #[derive(clap::Subcommand)] pub enum CliCommands { Debug, + DebugCrash, DebugHostname, DebugPipeServer, DebugWintun, diff --git a/rust/windows-client/src-tauri/src/client/debug_commands.rs b/rust/windows-client/src-tauri/src/client/debug_commands.rs index 178a59cdf..e61cfbfc7 100644 --- a/rust/windows-client/src-tauri/src/client/debug_commands.rs +++ b/rust/windows-client/src-tauri/src/client/debug_commands.rs @@ -8,6 +8,14 @@ use tokio::runtime::Runtime; // TODO: In tauri-plugin-deep-link, this is the identifier in tauri.conf.json const PIPE_NAME: &str = "dev.firezone.client"; +pub fn crash() -> Result<()> { + // `_` doesn't seem to work here, the log files end up empty + let _handles = crate::client::logging::setup("debug")?; + tracing::info!("started log (DebugCrash)"); + + panic!("purposely crashing to see if it shows up in logs"); +} + pub fn hostname() -> Result<()> { println!( "{:?}", diff --git a/rust/windows-client/src-tauri/src/client/logging.rs b/rust/windows-client/src-tauri/src/client/logging.rs index 5cf68be9a..e36ee4f4b 100755 --- a/rust/windows-client/src-tauri/src/client/logging.rs +++ b/rust/windows-client/src-tauri/src/client/logging.rs @@ -16,6 +16,9 @@ use tracing::subscriber::set_global_default; use tracing_log::LogTracer; use tracing_subscriber::{fmt, layer::SubscriberExt, reload, EnvFilter, Layer, Registry}; +/// If you don't store `Handles` in a variable, the file logger handle will drop immediately, +/// resulting in empty log files. +#[must_use] pub(crate) struct Handles { pub logger: file_logger::Handle, pub _reloader: reload::Handle,