-
Notifications
You must be signed in to change notification settings - Fork 572
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
Comments
In general, it is the responsibility of the opener of the writer to close it. |
@rs yes, agree. |
@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. |
What prevents you from adding the closing of the writer in an exit handler? |
It would be nice to have
Close() error
method defined onzerolog.Logger
. When it's called it checks ifwriter
implementsio.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 implementio.Closer
, so somebody can accidentally close them, which is not good 😕The text was updated successfully, but these errors were encountered: