rust-lang / log

Logging implementation for Rust
https://docs.rs/log
Apache License 2.0
2.12k stars 248 forks source link

Feature suggestion: fatal log level with fatal! macro #612

Closed ogwhic closed 6 months ago

ogwhic commented 6 months ago

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).

sfackler commented 6 months ago

I would suggest writing a panic hook that logs.

Thomasdezeeuw commented 6 months ago

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 ;)

ogwhic commented 6 months ago

I stand corrected. Thanks for the suggestion and link to log-panics. Closing the issue as the comments above are a better solution. :-)