1
0

Add log level parameter

This commit is contained in:
dump_stack() 2023-03-18 21:53:53 +00:00
parent 8bffea0aea
commit ae20a6d11d
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 19 additions and 1 deletions

18
main.go
View File

@ -36,6 +36,24 @@ type CLI struct {
Image ImageCmd `cmd:"" help:"manage images"` Image ImageCmd `cmd:"" help:"manage images"`
Version VersionFlag `name:"version" help:"print version information and quit"` Version VersionFlag `name:"version" help:"print version information and quit"`
LogLevel LogLevelFlag `enum:"debug,info,warn,error" default:"info"`
}
type LogLevelFlag string
func (loglevel LogLevelFlag) AfterApply() error {
switch loglevel {
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
case "info":
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case "warn":
zerolog.SetGlobalLevel(zerolog.WarnLevel)
case "error":
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
}
return nil
} }
type VersionFlag string type VersionFlag string

2
pew.go
View File

@ -50,7 +50,7 @@ type PewCmd struct {
func (cmd PewCmd) Run(g *Globals) (err error) { func (cmd PewCmd) Run(g *Globals) (err error) {
kcfg, err := config.ReadKernelConfig(g.Config.Kernels) kcfg, err := config.ReadKernelConfig(g.Config.Kernels)
if err != nil { if err != nil {
log.Print(err) log.Debug().Err(err).Msg("read kernel config")
} }
stop := time.Time{} // never stop stop := time.Time{} // never stop