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 <[email protected]>
  • Loading branch information
peter81git committed Nov 12, 2024
1 parent c1bfc6e commit 66bd611
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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,11 @@ 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 66bd611

Please sign in to comment.