Skip to content

Commit

Permalink
Create slog handler with the configured parsed log level
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Oct 13, 2023
1 parent 3f64d83 commit b65220a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd/courier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,16 @@ func main() {
config.Version = version
}

// configure our logger
loggerLevel := new(slog.LevelVar)
logHandler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: loggerLevel})
slog.SetDefault(slog.New(logHandler))

var level slog.Level
err := level.UnmarshalText([]byte(config.LogLevel))
if err != nil {
log.Fatalf("invalid log level %s", level)
os.Exit(1)
}
loggerLevel.Set(level)

// configure our logger
logHandler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level})
slog.SetDefault(slog.New(logHandler))

logger := slog.With("comp", "main")
logger.Info("starting courier", "version", version)
Expand Down

0 comments on commit b65220a

Please sign in to comment.