sfackler / rust-log-panics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should it flush the logger?

dekellum opened this issue · comments

(Found this crate on the way to prototyping a fatal! macro in dekellum/tao-log#1, which sort of solves the same problem, but from the opposite direction.)

Should the panic handler flush the logger after logging the panic? Maybe most logger implementations don't buffer messages, but if any did, then this would be important to persist the log message before terminating?

If the answer is no, then feel free to close. If the answer is yes, then would a PR be desired?

Flushing the logger before exit is the application's responsibility IMO.

In many applications like servers, a panic isn't going to shut down the whole server anyway, since it'll be contained to the offending request.

Thanks, I hadn't considered the one-thread-of-a-server use-case.

But that's not the only possible use, this could be setup on main, for a single-threaded server, no? Doesn't the severity of a panic! warrant "playing it safe" with a flush? Minor possible down side is performance of logging, but only if panics are so frequent so as to be a performance liability themselves, no?

The threaded-ness of a server doesn't really have anything to do with its approach towards panics, but again, it seems like if an application is worried about this, it can stick a guard object in main that flushes the logger if it wants.

Thanks and sorry if I'm being a pain here, but: wouldn't such a guard get Drop'd before the panic handler runs and the message is logged?

No, the panic handler runs before the program unwinds.

You'd need this drop guard anyway if the program has the ability to exit on its own.

OK, thanks.