Skip to content

Commit

Permalink
update logger
Browse files Browse the repository at this point in the history
  • Loading branch information
sayem314 committed Sep 27, 2024
1 parent 6ac94d8 commit 814f053
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions logger/zerolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ package logger

import (
"os"
"strings"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

func Initialize(logLevel string) {
level := zerolog.DebugLevel
func init() {
// Read the DEBUG environment variable to determine the log level
debugEnv := strings.ToLower(os.Getenv("DEBUG"))
level := zerolog.InfoLevel

switch logLevel {
case "debug":
if debugEnv == "true" {
level = zerolog.DebugLevel
case "info":
level = zerolog.InfoLevel
case "warn":
level = zerolog.WarnLevel
case "error":
level = zerolog.ErrorLevel
default:
log.Warn().Msgf("Invalid log level '%s', defaulting to Debug level", logLevel)
}

zerolog.SetGlobalLevel(level)
// Create a new logger with the desired level
logger := zerolog.New(zerolog.ConsoleWriter{
Out: os.Stderr,
TimeFormat: "2006-01-02 15:04:05",
NoColor: false,
}).Level(level).With().Timestamp().Logger()

log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
// Assign the new logger to the package-level logger
log.Logger = logger
}

func Debug(msg string, args ...interface{}) {
Expand Down

0 comments on commit 814f053

Please sign in to comment.