mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
feat(log): support setting minimum log level with GUM_LOG_LEVEL (#723)
closes #490
This commit is contained in:
parent
c868aa1c6c
commit
1ffe8b7e70
2 changed files with 9 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue