Skip to content

panic message as key, info to context #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions my-seq-logger/src/seq_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ pub struct SeqLogger {

impl SeqLogger {
pub fn enable_from_connection_string(settings: Arc<dyn SeqSettings + Send + Sync + 'static>) {
std::panic::set_hook(Box::new(|itm| {
std::panic::set_hook(Box::new(|panic_info| {
let ctx = if let Some(location) = itm.location() {
LogEventCtx::new().add("Location", format!("{}", location))
} else {
LogEventCtx::new()
};

ctx.add_object("PanicInfo", panic_info);

my_logger_core::LOGGER.write_fatal_error(
"Panic Handler",
format!("Panic info: {:?}", itm),
"Handle panic in hook",
ctx,
);
}));
Expand Down
Loading