Skip to content

Commit

Permalink
fix: replace text handler with the default one
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Jan 24, 2025
1 parent afa164b commit ec9e7b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/trivy-db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
12 changes: 6 additions & 6 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log/slog"
"os"
)

// Logger is an alias for slog.Logger
Expand Down Expand Up @@ -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...)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit ec9e7b3

Please sign in to comment.