Skip to content

Commit

Permalink
feat(log): support setting minimum log level with GUM_LOG_LEVEL (#723)
Browse files Browse the repository at this point in the history
closes #490
  • Loading branch information
caarlos0 authored Nov 18, 2024
1 parent c868aa1 commit 1ffe8b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions log/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func (o Options) Run() error {
l.SetPrefix(o.Prefix)
l.SetLevel(-math.MaxInt32) // log all levels
l.SetReportTimestamp(o.Time != "")
if o.MinLevel != "" {
lvl, err := log.ParseLevel(o.MinLevel)
if err != nil {
return err
}
l.SetLevel(lvl)
}

timeFormats := map[string]string{
"layout": time.Layout,
Expand Down
2 changes: 2 additions & 0 deletions log/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Options struct {
Structured bool `short:"s" help:"Use structured logging" xor:"format,structured"`
Time string `short:"t" help:"The time format to use (kitchen, layout, ansic, rfc822, etc...)" default:""`

MinLevel string `help:"Minimal level to show" default:"" env:"GUM_LOG_LEVEL"`

LevelStyle style.Styles `embed:"" prefix:"level." help:"The style of the level being used" set:"defaultBold=true" envprefix:"GUM_LOG_LEVEL_"` //nolint:staticcheck
TimeStyle style.Styles `embed:"" prefix:"time." help:"The style of the time" envprefix:"GUM_LOG_TIME_"`
PrefixStyle style.Styles `embed:"" prefix:"prefix." help:"The style of the prefix" set:"defaultBold=true" set:"defaultFaint=true" envprefix:"GUM_LOG_PREFIX_"` //nolint:staticcheck
Expand Down

0 comments on commit 1ffe8b7

Please sign in to comment.