Files
linuxkit/vendor/github.com/docker/infrakit/pkg/cli/logging.go
Rolf Neugebauer 2ab909fcbd vendor: Update to a new version of InfraKit
This pulls in another slew of other packages.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
2017-04-04 16:07:53 +01:00

33 lines
955 B
Go

package cli
import (
"github.com/spf13/pflag"
"github.com/Sirupsen/logrus"
logutil "github.com/docker/infrakit/pkg/log"
)
// DefaultLogLevel is the default log level value.
var DefaultLogLevel = len(logrus.AllLevels) - 2
// SetLogLevel adjusts the logrus level.
func SetLogLevel(level int) {
if level > len(logrus.AllLevels)-1 {
level = len(logrus.AllLevels) - 1
} else if level < 0 {
level = 0
}
logrus.SetLevel(logrus.AllLevels[level])
}
// Flags returns the set of logging flags
func Flags(o *logutil.Options) *pflag.FlagSet {
f := pflag.NewFlagSet("logging", pflag.ExitOnError)
f.IntVar(&o.Level, "log", o.Level, "log level")
f.BoolVar(&o.Stdout, "log-stdout", o.Stdout, "log to stdout")
f.BoolVar(&o.CallFunc, "log-caller", o.CallFunc, "include caller function")
f.BoolVar(&o.CallStack, "log-stack", o.CallStack, "include caller stack")
f.StringVar(&o.Format, "log-format", o.Format, "log format: logfmt|term|json")
return f
}