From ca523657807d83e24ee17f5bce2e4b76cbc56c23 Mon Sep 17 00:00:00 2001 From: Daniel Zhang Date: Tue, 24 Jan 2017 18:16:16 +0800 Subject: [PATCH] Allow specifying the log level Signed-off-by: Daniel Zhang --- cmd/containerd/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index f6a5ee8..560ccf2 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -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 {