mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
wip(windows): make sure app panics show up in the logs (#3085)
Related to this discussion https://github.com/firezone/firezone/pull/2990#discussion_r1439629571 Add a dependency on the `tracing-panic` crate. This is about 100 lines of code that adds a panic handle so app panics get a line number, file name, etc. in the logs. No backtrace I think since we stripe symbols for release builds. I _think_ the line numbers are baked into the panic macro so those might still stay. @conectado I should remove the debug command before closing it, right?
This commit is contained in:
11
rust/Cargo.lock
generated
11
rust/Cargo.lock
generated
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -12,6 +12,7 @@ pub struct Cli {
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum CliCommands {
|
||||
Debug,
|
||||
DebugCrash,
|
||||
DebugHostname,
|
||||
DebugPipeServer,
|
||||
DebugWintun,
|
||||
|
||||
@@ -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!(
|
||||
"{:?}",
|
||||
|
||||
@@ -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<EnvFilter, Registry>,
|
||||
|
||||
Reference in New Issue
Block a user