Skip to content

Commit

Permalink
Fix logging not working when not running from terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Feb 4, 2024
1 parent e3f63b8 commit 3a3c960
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,17 @@ func init() {
_ = level.UnmarshalText([]byte(viper.GetString("log")))

handlers := make([]slog.Handler, 0)
handlers = append(handlers, tint.NewHandler(os.Stdout, &tint.Options{
Level: level,
AddSource: true,
TimeFormat: time.RFC3339,
}))

if _, err = os.Stdout.Stat(); err == nil {
// Only add the stdout handler if it is writable.
// Otherwise, the fanout handler would have the first handler error,
// and will not get to use the file handler.
handlers = append(handlers, tint.NewHandler(os.Stdout, &tint.Options{
Level: level,
AddSource: true,
TimeFormat: time.RFC3339,
}))
}

if viper.GetString("log-file") != "" {
logFile := &lumberjack.Logger{
Expand Down

0 comments on commit 3a3c960

Please sign in to comment.