From 16bae880ea6f0328177cfad50ae9ef5853583eb6 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Sat, 20 Oct 2018 17:36:07 +0800 Subject: [PATCH] fix data race issue --- formatters/text_formatter.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/formatters/text_formatter.go b/formatters/text_formatter.go index 5f0937d..63d0391 100644 --- a/formatters/text_formatter.go +++ b/formatters/text_formatter.go @@ -11,6 +11,7 @@ import ( "github.com/fangdingjun/go-log" ) +/* var ( fmtBuffer = sync.Pool{ New: func() interface{} { @@ -18,6 +19,7 @@ var ( }, } ) +*/ // TextFormatter is a text line formatter type TextFormatter struct { @@ -54,9 +56,10 @@ func (f *TextFormatter) Format(level log.Level, msg string, logger *log.Logger) f.pid = []byte(strconv.Itoa(os.Getpid())) }) - buf := fmtBuffer.Get().(*bytes.Buffer) - buf.Reset() - defer fmtBuffer.Put(buf) + //buf := fmtBuffer.Get().(*bytes.Buffer) + //buf.Reset() + //defer fmtBuffer.Put(buf) + buf := new(bytes.Buffer) // timestamp timeStr := time.Now().Format(f.TimeFormat)