Sets a global panic hook that logs panic details with backtrace using tracing. Useful for Rust services needing structured panic logs.
// Source: https://github.com/constructorfabric/gears-rust | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
use std::sync::Once;
static PANIC_HOOK_INIT: Once = Once::new();
pub fn init_panic_tracing() {
PANIC_HOOK_INIT.call_once(|| {
std::panic::set_hook(Box::new(|panic_info| {
let backtrace = std::backtrace::Backtrace::force_capture();
let location = panic_info.location().map_or_else(
|| "unknown location".to_owned(),
|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column()),
);
let payload = if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
(*s).to_owne
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key