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

ConsoleWriter: reset buffer before returning it to the pool #119

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
}

consoleDefaultTimeFormat = time.Kitchen
consoleDefaultFormatter = func(i interface{}) string { return fmt.Sprintf("%s", i) }
consoleDefaultPartsOrder = func() []string {
return []string{
TimestampFieldName,
Expand Down Expand Up @@ -113,7 +112,10 @@ func (w ConsoleWriter) Write(p []byte) (n int, err error) {
}

var buf = consoleBufPool.Get().(*bytes.Buffer)
defer consoleBufPool.Put(buf)
defer func() {
buf.Reset()
consoleBufPool.Put(buf)
}()

var evt map[string]interface{}
p = decodeIfBinaryToBytes(p)
Expand All @@ -130,9 +132,12 @@ func (w ConsoleWriter) Write(p []byte) (n int, err error) {

w.writeFields(evt, buf)

buf.WriteByte('\n')
buf.WriteTo(w.Out)
return len(p), nil
err = buf.WriteByte('\n')
if err != nil {
return n, err
}
_, err = buf.WriteTo(w.Out)
return len(p), err
}

// writeFields appends formatted key-value pairs to buf.
Expand Down