Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(log): support setting minimum log level with GUM_LOG_LEVEL #723

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading