Closed ogwhic closed 6 months ago
I would suggest writing a panic hook that logs.
I would suggest writing a panic hook that logs.
Some one even wrote a crate to do this already: https://crates.io/crates/log-panics ;)
I stand corrected. Thanks for the suggestion and link to log-panics. Closing the issue as the comments above are a better solution. :-)
A fatal! macro that behaves like panic! but logs (and flushes) the error before exiting to act as a drop in replacement to panic! would be useful.
Currently logging fatal errors before exiting is less succinct and the temptation to use panic! could result in a loss of diagnostic info. E.g., panic! messages missing from log files or external logging infrastructure.
fatal! could log the error then panic! and if the logger implementation writes to stderr/stdout the implementation could choose not to log fatal errors and simply rely on the standard panic! behaviour (to avoid duplicate messages).