Skip to content

Commit

Permalink
Add Log Level parser to main
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed Aug 16, 2024
1 parent 52511d8 commit 10d3d3e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

"ella.to/bus/server"
Expand Down Expand Up @@ -85,7 +86,29 @@ func getAddr(defaultValue string) string {
return value
}

func getLogLevel() slog.Level {
value := os.Getenv("BUS_LOG_LEVEL")
if value == "" {
return slog.LevelInfo
}

switch strings.ToLower(value) {
case "debug":
return slog.LevelDebug
case "info":
return slog.LevelInfo
case "warn":
return slog.LevelWarn
case "error":
return slog.LevelError
default:
return slog.LevelInfo
}
}

func main() {
slog.SetLogLoggerLevel(getLogLevel())

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down

0 comments on commit 10d3d3e

Please sign in to comment.