Skip to content

Logging Panic, and display log on panic #91

@Spooky-Firefox

Description

@Spooky-Firefox

By adding panic hook that logs the panic and then return to the default panic handler would be useful for debugging when users who manage to crash the application require assistance. This could possibly be implemented as bellow

use std::panic;
use log::*;

let default_panic = panic::take_hook()

panic::set_hook(Box::new(|info| {
    error!("{}",info);
    default_panic(info);
}));

Its behavior can be updated to open the log file on panic, might be useful if its distributed as a gui application.
The opener crate open a file with the os default application https://docs.rs/opener/latest/opener/fn.open.html#

use std::panic;
use log::*;
use opener::open;

let default_panic = panic::take_hook()

panic::set_hook(Box::new(|info| {
    error!("{}",info);
    open("../output.log");
    default_panic(info);
}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions