Skip to content

Commit 66bd611

Browse files
committed
Add timestamp to warn log
Signed-off-by: peter81git <44998875+peter81git@users.noreply.github.com>
1 parent c1bfc6e commit 66bd611

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/context/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package context
88

99
import (
1010
"fmt"
11+
"time"
1112

1213
"github.com/jaypipes/ghw/pkg/option"
1314
"github.com/jaypipes/ghw/pkg/snapshot"
@@ -173,6 +174,11 @@ func (ctx *Context) Teardown() error {
173174
return snapshot.Cleanup(ctx.snapshotUnpackedPath)
174175
}
175176

177+
// Warn Send warnings to log with timestamp
176178
func (ctx *Context) Warn(msg string, args ...interface{}) {
177179
ctx.alert.Printf("WARNING: "+msg, args...)
180+
location, _ := time.LoadLocation("UTC")
181+
timestamp := time.Now().In(location).Format("2006-01-02T15:04:05.000000-07:00")
182+
formatedMsg := fmt.Sprintf("[%s] WARNING: %s", timestamp, msg)
183+
ctx.alert.Printf(formatedMsg, args...)
178184
}

0 commit comments

Comments
 (0)