Skip to content

Properly close the writer and wait for all writes to finish - #1092

Open
adieu wants to merge 1 commit into
sirupsen:masterfrom
adieu:close-writer
Open

Properly close the writer and wait for all writes to finish#1092
adieu wants to merge 1 commit into
sirupsen:masterfrom
adieu:close-writer

Conversation

@adieu

@adieu adieu commented Jan 23, 2020

Copy link
Copy Markdown

I use logger.Writer() as io.Writer for the output of my program and found that sometimes when the program exit too fast, some output wouldn't be displayed even if I close the writer before exit.

After reading writer.go I found that when we call writer.Close() we don't wait for entry.writerScanner() which runs in another goroutine to finish.

This commit adds WriterLevelWithClose which returns a closeFunc to properly close the writer and reader.

Eventually we might have to modify Writer and WriterLevel to return the closeFunc too which is not backward compatible or we might wrap the writer and return an io.WriteCloser instead.

@medoraemon

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants