From ec9e7b33db27064db2bff1deb4ee583a488cc371 Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Fri, 24 Jan 2025 15:22:29 +0400 Subject: [PATCH] fix: replace text handler with the default one Signed-off-by: knqyf263 --- cmd/trivy-db/main.go | 2 +- pkg/log/log.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/trivy-db/main.go b/cmd/trivy-db/main.go index 310388ab..d9f205a8 100644 --- a/cmd/trivy-db/main.go +++ b/cmd/trivy-db/main.go @@ -16,7 +16,7 @@ func main() { app := ac.NewApp(version) err := app.Run(os.Args) if err != nil { - log.Error("Failed to run app", log.Err(err)) + log.Errorf("%+v", err) os.Exit(1) } } diff --git a/pkg/log/log.go b/pkg/log/log.go index 72864c38..c41fa0f9 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log/slog" - "os" ) // Logger is an alias for slog.Logger @@ -34,6 +33,10 @@ func Error(msg string, args ...any) { defaultLogger.Error(msg, args...) } +func Errorf(format string, args ...any) { + defaultLogger.Error(fmt.Sprintf(format, args...)) +} + func Debug(msg string, args ...any) { defaultLogger.Debug(msg, args...) } @@ -57,13 +60,10 @@ type PrefixHandler struct { } func init() { - opts := &slog.HandlerOptions{ - Level: slog.LevelDebug, - } - baseHandler := slog.NewTextHandler(os.Stdout, opts) + slog.SetLogLoggerLevel(slog.LevelDebug) prefixHandler := &PrefixHandler{ prefix: "", - handler: baseHandler, + handler: slog.Default().Handler(), } defaultLogger = slog.New(prefixHandler) }