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

Should it flush the logger? #4

Closed
dekellum opened this issue Mar 29, 2019 · 6 comments
Closed

Should it flush the logger? #4

dekellum opened this issue Mar 29, 2019 · 6 comments

Comments

@dekellum
Copy link

(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
Copy link
Owner

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
Copy link
Author

dekellum commented Mar 29, 2019

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

OK, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants