From 4cec9341d5812957f3f34bafeef1c11036e286c0 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 5 May 2023 17:55:50 +0200 Subject: pkg/log: don't prepend timestamp twice golog.Printf also prepends time, so we only need to do it for log caching. --- pkg/log/log.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pkg') diff --git a/pkg/log/log.go b/pkg/log/log.go index 2a2fd6481..aee63e6e2 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -90,9 +90,6 @@ func Fatalf(msg string, args ...interface{}) { func writeMessage(v int, severity, msg string, args ...interface{}) { var sb strings.Builder - if prependTime { - sb.WriteString(time.Now().Format("2006/01/02 15:04:05 ")) - } if severity != "" { fmt.Fprintf(&sb, "[%s] ", severity) } @@ -110,7 +107,11 @@ func writeRawMessage(v int, msg string) { if cacheMem < 0 { panic("log cache size underflow") } - cacheEntries[cachePos] = msg + timeStr := "" + if prependTime { + timeStr = time.Now().Format("2006/01/02 15:04:05 ") + } + cacheEntries[cachePos] = timeStr + msg cacheMem += len(cacheEntries[cachePos]) cachePos++ if cachePos == len(cacheEntries) { -- cgit mrf-deployment