ConsoleWriter: reset buffer before returning it to the pool (#119)
The buffers put back into the pool should be equivalent to those generated by the `New` function.
This commit is contained in:
parent
8747b7b3a5
commit
7179aeef58
15
console.go
15
console.go
|
@ -37,7 +37,6 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleDefaultTimeFormat = time.Kitchen
|
consoleDefaultTimeFormat = time.Kitchen
|
||||||
consoleDefaultFormatter = func(i interface{}) string { return fmt.Sprintf("%s", i) }
|
|
||||||
consoleDefaultPartsOrder = func() []string {
|
consoleDefaultPartsOrder = func() []string {
|
||||||
return []string{
|
return []string{
|
||||||
TimestampFieldName,
|
TimestampFieldName,
|
||||||
|
@ -113,7 +112,10 @@ func (w ConsoleWriter) Write(p []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf = consoleBufPool.Get().(*bytes.Buffer)
|
var buf = consoleBufPool.Get().(*bytes.Buffer)
|
||||||
defer consoleBufPool.Put(buf)
|
defer func() {
|
||||||
|
buf.Reset()
|
||||||
|
consoleBufPool.Put(buf)
|
||||||
|
}()
|
||||||
|
|
||||||
var evt map[string]interface{}
|
var evt map[string]interface{}
|
||||||
p = decodeIfBinaryToBytes(p)
|
p = decodeIfBinaryToBytes(p)
|
||||||
|
@ -130,9 +132,12 @@ func (w ConsoleWriter) Write(p []byte) (n int, err error) {
|
||||||
|
|
||||||
w.writeFields(evt, buf)
|
w.writeFields(evt, buf)
|
||||||
|
|
||||||
buf.WriteByte('\n')
|
err = buf.WriteByte('\n')
|
||||||
buf.WriteTo(w.Out)
|
if err != nil {
|
||||||
return len(p), nil
|
return n, err
|
||||||
|
}
|
||||||
|
_, err = buf.WriteTo(w.Out)
|
||||||
|
return len(p), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeFields appends formatted key-value pairs to buf.
|
// writeFields appends formatted key-value pairs to buf.
|
||||||
|
|
Loading…
Reference in New Issue