Allow specifying the log level
Signed-off-by: Daniel Zhang <jmzwcn@gmail.com>
This commit is contained in:
		@@ -48,6 +48,11 @@ high performance container runtime
 | 
				
			|||||||
			Name:  "debug",
 | 
								Name:  "debug",
 | 
				
			||||||
			Usage: "enable debug output in logs",
 | 
								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{
 | 
							cli.StringFlag{
 | 
				
			||||||
			Name:  "root",
 | 
								Name:  "root",
 | 
				
			||||||
			Usage: "containerd state directory",
 | 
								Usage: "containerd state directory",
 | 
				
			||||||
@@ -78,6 +83,14 @@ high performance container runtime
 | 
				
			|||||||
		if context.GlobalBool("debug") {
 | 
							if context.GlobalBool("debug") {
 | 
				
			||||||
			logrus.SetLevel(logrus.DebugLevel)
 | 
								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
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	app.Action = func(context *cli.Context) error {
 | 
						app.Action = func(context *cli.Context) error {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user