Allow specifying the log level

Signed-off-by: Daniel Zhang <jmzwcn@gmail.com>
This commit is contained in:
Daniel Zhang 2017-01-24 18:16:16 +08:00
parent 3b79682548
commit ca52365780
1 changed files with 13 additions and 0 deletions

View File

@ -48,6 +48,11 @@ high performance container runtime
Name: "debug",
Usage: "enable debug output in logs",
},
cli.StringFlag{
Name: "log-level",
Usage: "Set the logging level [debug, info, warn, error, fatal, panic]",
Value: "info",
},
cli.StringFlag{
Name: "root",
Usage: "containerd state directory",
@ -78,6 +83,14 @@ high performance container runtime
if context.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
if logLevel := context.GlobalString("log-level"); logLevel != "" {
lvl, err := logrus.ParseLevel(logLevel)
if err != nil {
lvl = logrus.InfoLevel
fmt.Fprintf(os.Stderr, "Unable to parse logging level: %s\n, and being defaulted to info", logLevel)
}
logrus.SetLevel(lvl)
}
return nil
}
app.Action = func(context *cli.Context) error {