From 95cb00d1ffccfb9043ac5d91ff8103bbb9befae8 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 15 Jul 2022 09:27:28 +0000 Subject: pkg/debugtracer: add the ability to capture time in logs --- pkg/debugtracer/debug.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'pkg/debugtracer/debug.go') diff --git a/pkg/debugtracer/debug.go b/pkg/debugtracer/debug.go index 99a95fd83..10259e788 100644 --- a/pkg/debugtracer/debug.go +++ b/pkg/debugtracer/debug.go @@ -8,6 +8,7 @@ import ( "io" "path/filepath" "testing" + "time" "github.com/google/syzkaller/pkg/osutil" ) @@ -18,6 +19,7 @@ type DebugTracer interface { } type GenericTracer struct { + WithTime bool TraceWriter io.Writer OutDir string } @@ -30,7 +32,13 @@ type NullTracer struct { } func (gt *GenericTracer) Log(msg string, args ...interface{}) { - fmt.Fprintf(gt.TraceWriter, msg+"\n", args...) + if gt.WithTime { + timeStr := time.Now().Format("02-Jan-2006 15:04:05") + newArgs := append([]interface{}{timeStr}, args...) + fmt.Fprintf(gt.TraceWriter, "%s: "+msg+"\n", newArgs...) + } else { + fmt.Fprintf(gt.TraceWriter, msg+"\n", args...) + } } func (gt *GenericTracer) SaveFile(filename string, data []byte) { -- cgit mrf-deployment