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

closes #490
This commit is contained in:
Carlos Alexandro Becker 2024-11-18 14:02:55 -03:00 committed by GitHub
commit 1ffe8b7e70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -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,

View file

@ -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