k3s/pkg/cli/cmds/debug.go

32 lines
598 B
Go
Raw Normal View History

2020-07-10 17:34:00 +00:00
package cmds
import (
"github.com/rancher/k3s/pkg/version"
"github.com/rancher/spur/cli"
"github.com/sirupsen/logrus"
)
var (
Debug = false
DebugFlag = cli.BoolFlag{
Name: "debug",
Usage: "(logging) Turn on debug logs",
Destination: &Debug,
EnvVars: []string{version.ProgramUpper + "_DEBUG"},
}
)
func DebugContext(f func(*cli.Context) error) func(ctx *cli.Context) error {
return func(ctx *cli.Context) error {
if f != nil {
if err := f(ctx); err != nil {
return err
}
}
if Debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
}