Skip to content

Commit

Permalink
fix: fixed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mherwig committed Jun 25, 2024
1 parent 6645a9f commit 33f0823
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
3 changes: 3 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"golaris/internal/cache"
"golaris/internal/config"
"golaris/internal/kafka"
"golaris/internal/log"
"golaris/internal/mock"
"golaris/internal/mongo"
"golaris/internal/scheduler"
Expand All @@ -20,6 +21,8 @@ var serveCmd = &cobra.Command{
func initialize() {
config.Load()

log.SetLogLevel(config.Current.LogLevel)

cache.Initialize()
mongo.Initialize()
kafka.Initialize()
Expand Down
20 changes: 0 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
package main

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golaris/cmd"
"golaris/internal/config"
"os"
)

func init() {
setLogLevel(config.Current.LogLevel)
}

func setLogLevel(level string) {
logLevel, err := zerolog.ParseLevel(level)
if err != nil {
logLevel = zerolog.InfoLevel
log.Info().Msgf("Invalid log level %s. Info log level is used", logLevel)
}

log.Logger = zerolog.New(os.Stdout).Level(logLevel).With().Timestamp().Logger()
if logLevel == zerolog.DebugLevel {
log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stdout})
}
}
func main() {
cmd.Execute()
}

0 comments on commit 33f0823

Please sign in to comment.