aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-10-10 12:35:38 +0200
committerDmitry Vyukov <dvyukov@google.com>2016-10-10 12:35:38 +0200
commit3bea0ca43ed9cec76f7d36080cf0a645d320851d (patch)
treec219a5913497903d77f47939cbd05199a87b6df0
parent98d3616671fa4a539a1028bd2613a76388f95999 (diff)
log: fix test
-rw-r--r--log/log.go7
-rw-r--r--log/log_test.go1
2 files changed, 7 insertions, 1 deletions
diff --git a/log/log.go b/log/log.go
index cf1bad78a..9fff33497 100644
--- a/log/log.go
+++ b/log/log.go
@@ -25,6 +25,7 @@ var (
cacheMaxMem int
cachePos int
cacheEntries []string
+ prependTime bool // for testing
)
// EnableCaching enables in memory caching of log output.
@@ -73,7 +74,11 @@ func Logf(v int, msg string, args ...interface{}) {
if cacheMem < 0 {
panic("log cache size underflow")
}
- cacheEntries[cachePos] = fmt.Sprintf(time.Now().Format("2006/01/02 15:04:05 ")+msg, args...)
+ timeStr := ""
+ if prependTime {
+ timeStr = time.Now().Format("2006/01/02 15:04:05 ")
+ }
+ cacheEntries[cachePos] = fmt.Sprintf(timeStr+msg, args...)
cacheMem += len(cacheEntries[cachePos])
cachePos++
if cachePos == len(cacheEntries) {
diff --git a/log/log_test.go b/log/log_test.go
index e21a8a78d..d179f0b87 100644
--- a/log/log_test.go
+++ b/log/log_test.go
@@ -21,6 +21,7 @@ func TestCaching(t *testing.T) {
{"jjjjjjjjjjjjjjjjjjjjjjjjj", "jjjjjjjjjjjjjjjjjjjjjjjjj\n"},
}
EnableLogCaching(4, 20)
+ prependTime = false
for _, test := range tests {
Logf(1000, test.str)
out := CachedLogOutput()