Skip to content

Commit

Permalink
fixed logger not working when there is no stdout attached for redirec…
Browse files Browse the repository at this point in the history
…ting output
  • Loading branch information
hectorgimenez committed Mar 24, 2024
1 parent 74f229a commit 8981727
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/koolo/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ func NewLogger(debug bool, logDir string) (*slog.Logger, error) {
}

fileName := "koolo-log-" + time.Now().Format("2006-01-02-15-04-05") + ".txt"
logFileHandler, err := os.Create(logDir + "/" + fileName)
lfh, err := os.Create(logDir + "/" + fileName)
if err != nil {
return nil, err
}
logFileHandler = lfh

level := slog.LevelDebug
if !debug {
Expand All @@ -38,7 +39,7 @@ func NewLogger(debug bool, logDir string) (*slog.Logger, error) {
Level: level,
}

handler := slog.NewTextHandler(io.MultiWriter(os.Stdout, logFileHandler), opts)
handler := slog.NewTextHandler(io.MultiWriter(logFileHandler, os.Stdout), opts)

return slog.New(handler), nil
}
Expand Down

0 comments on commit 8981727

Please sign in to comment.