Skip to content
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

Logging Panic, and display log on panic #91

Open
Spooky-Firefox opened this issue Oct 10, 2024 · 0 comments
Open

Logging Panic, and display log on panic #91

Spooky-Firefox opened this issue Oct 10, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Spooky-Firefox
Copy link
Collaborator

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);
}));
@Spooky-Firefox Spooky-Firefox added the enhancement New feature or request label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant