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

Close() logger method #10

Closed
tyranron opened this issue Jul 14, 2017 · 4 comments
Closed

Close() logger method #10

tyranron opened this issue Jul 14, 2017 · 4 comments

Comments

@tyranron
Copy link
Contributor

It would be nice to have Close() error method defined on zerolog.Logger. When it's called it checks if writer implements io.Closer interface and if yes: return l.w.Close().

This is not something required when we use os.Stdout/os.Stderr as writer. But is very helpful for buffered log writers to file, to make sure that every byte buffered in will be written to file before program exists.
Currently it's possible with treating such log writer separately from logger, which isn't comfortable as makes us to deal with one more dependency across the code.

However, os.Stdout/os.Stderr also implement io.Closer, so somebody can accidentally close them, which is not good 😕

@rs
Copy link
Owner

rs commented Aug 2, 2017

In general, it is the responsibility of the opener of the writer to close it.

@tyranron
Copy link
Contributor Author

tyranron commented Aug 2, 2017

@rs yes, agree.

@tyranron tyranron closed this as completed Aug 2, 2017
@ttc0419
Copy link

ttc0419 commented Apr 14, 2024

@rs Hi, it's common that the logger writer is created by a factory function. In this case we will lose the reference of the writer and we only get the logger. For the diode writer, if we do not close the writer before exits, the last a few logs will be missing and they are often curial for debugging. Please reconsider this feature request, thanks.

@rs
Copy link
Owner

rs commented Apr 14, 2024

What prevents you from adding the closing of the writer in an exit handler?

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

3 participants