From 9806a43783f240e0d15f8c2e2fdb92a718b3533c Mon Sep 17 00:00:00 2001 From: JessonChan Date: Wed, 3 Feb 2016 15:03:37 +0800 Subject: [PATCH] make more fast --- logs/file.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/logs/file.go b/logs/file.go index 6001b982..ae58fc29 100644 --- a/logs/file.go +++ b/logs/file.go @@ -119,10 +119,11 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error { return nil } h, d := formatTimeHeader(when) + msg = string(h) + msg + "\n" if w.Rotate { - if w.needRotate(len(h)+len(msg)+1, d) { + if w.needRotate(len(msg), d) { w.Lock() - if w.needRotate(len(h)+len(msg)+1, d) { + if w.needRotate(len(msg), d) { if err := w.doRotate(when); err != nil { fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err) } @@ -132,7 +133,7 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error { } w.Lock() - _, err := w.fileWriter.Write(append(append(h, msg...), '\n')) + _, err := w.fileWriter.Write([]byte(msg)) if err == nil { w.maxLinesCurLines++ w.maxSizeCurSize += len(msg)