Skip to content

Commit

Permalink
Add timestamp to warn log
Browse files Browse the repository at this point in the history
Signed-off-by: peter81git <44998875+peter81git@users.noreply.github.com>
  • Loading branch information
peter81git committed Nov 13, 2024
1 parent c1bfc6e commit 6ffba35
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package context

import (
"fmt"
"time"

"github.com/jaypipes/ghw/pkg/option"
"github.com/jaypipes/ghw/pkg/snapshot"
Expand Down Expand Up @@ -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...)
}

0 comments on commit 6ffba35

Please sign in to comment.