mirror of
https://github.com/wez/wezterm.git
synced 2025-01-08 23:17:36 +03:00
capture panic backtrace to log file
This commit is contained in:
parent
97005b8c1c
commit
efcc4b48c1
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1090,6 +1090,7 @@ dependencies = [
|
||||
name = "env-bootstrap"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"chrono",
|
||||
"cocoa",
|
||||
"config",
|
||||
|
@ -7,6 +7,7 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3"
|
||||
chrono = {version="0.4", features=["unstable-locales"]}
|
||||
config = { path = "../config" }
|
||||
dirs-next = "2.0"
|
||||
|
@ -136,8 +136,31 @@ pub fn set_lang_from_locale() {
|
||||
}
|
||||
}
|
||||
|
||||
fn register_panic_hook() {
|
||||
let default_hook = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |info| {
|
||||
let payload = info.payload();
|
||||
let payload = payload.downcast_ref::<&str>().unwrap_or(&"!?");
|
||||
let bt = backtrace::Backtrace::new();
|
||||
if let Some(loc) = info.location() {
|
||||
log::error!(
|
||||
"panic at {}:{}:{} - {}\n{:?}",
|
||||
loc.file(),
|
||||
loc.line(),
|
||||
loc.column(),
|
||||
payload,
|
||||
bt
|
||||
);
|
||||
} else {
|
||||
log::error!("panic - {}\n{:?}", payload, bt);
|
||||
}
|
||||
default_hook(info);
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn bootstrap() {
|
||||
setup_logger();
|
||||
register_panic_hook();
|
||||
|
||||
set_wezterm_executable();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user