Skip to content

Commit

Permalink
Update logging to print to console when logpath is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
aminst committed Oct 31, 2023
1 parent c525887 commit fd3a68f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/utils/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"os"
"time"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand All @@ -14,7 +15,10 @@ func InitLogging(isLogEnabled bool, logPath string) {
zerolog.SetGlobalLevel(zerolog.Disabled)
}

logFile, _ := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)

log.Logger = log.Output(logFile)
if logPath == "" {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339})
} else {
logFile, _ := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
log.Logger = log.Output(logFile)
}
}

0 comments on commit fd3a68f

Please sign in to comment.