sfackler / rust-log-panics

Apache License 2.0
52 stars 14 forks source link

Should it flush the logger? #4

Closed dekellum closed 5 years ago

dekellum commented 5 years ago

(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?

sfackler commented 5 years ago

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.

dekellum commented 5 years ago

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?

sfackler commented 5 years ago

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.

dekellum commented 5 years ago

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?

sfackler commented 5 years ago

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.

dekellum commented 5 years ago

OK, thanks.