Skip to content

Commit

Permalink
configure log level with env var (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh authored Aug 9, 2024
1 parent d26a705 commit c3adc02
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gcp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ package init

import (
"log/slog"
"os"

"github.com/chainguard-dev/clog"
"github.com/chainguard-dev/clog/gcp"
)

// Set up structured logging at Info+ level.
// TODO: Make the level configurable by env var or flag; or just remove the init package.
func init() { slog.SetDefault(slog.New(gcp.NewHandler(slog.LevelInfo))) }
func init() {
level := slog.LevelInfo
if e, ok := os.LookupEnv("LOG_LEVEL"); ok {
if err := level.UnmarshalText([]byte(e)); err != nil {
clog.Fatalf("slog: invalid log level: %v", err)
}
}
slog.SetDefault(slog.New(gcp.NewHandler(level)))
}

0 comments on commit c3adc02

Please sign in to comment.