From 6ffba35723d2087164bdf365c266937373433625 Mon Sep 17 00:00:00 2001 From: peter81git <44998875+peter81git@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:55:25 +0000 Subject: [PATCH] Add timestamp to warn log Signed-off-by: peter81git <44998875+peter81git@users.noreply.github.com> --- pkg/context/context.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/context/context.go b/pkg/context/context.go index fb8de528..4e7c9517 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -8,6 +8,7 @@ package context import ( "fmt" + "time" "github.com/jaypipes/ghw/pkg/option" "github.com/jaypipes/ghw/pkg/snapshot" @@ -173,6 +174,10 @@ func (ctx *Context) Teardown() error { return snapshot.Cleanup(ctx.snapshotUnpackedPath) } +// Warn Send warnings to log with timestamp func (ctx *Context) Warn(msg string, args ...interface{}) { - ctx.alert.Printf("WARNING: "+msg, args...) + location, _ := time.LoadLocation("UTC") + timestamp := time.Now().In(location).Format("2006-01-02T15:04:05.000000-07:00") + formatedMsg := fmt.Sprintf("[%s] WARNING: %s", timestamp, msg) + ctx.alert.Printf(formatedMsg, args...) }