Replace --debug with --log-level

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2015-01-21 16:16:44 -08:00
parent 027f8ed44a
commit 5200e3e764
1 changed files with 8 additions and 6 deletions

14
main.go
View File

@ -25,19 +25,21 @@ func main() {
app.Email = "" app.Email = ""
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.BoolFlag{ cli.StringFlag{
Name: "debug", Name: "log-level, l",
Usage: "debug mode", Value: "info",
EnvVar: "DEBUG", Usage: fmt.Sprintf("Log level (options: debug, info, warn, error, fatal, panic)"),
}, },
} }
// logs // logs
app.Before = func(c *cli.Context) error { app.Before = func(c *cli.Context) error {
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
if c.Bool("debug") { level, err := log.ParseLevel(c.String("log-level"))
log.SetLevel(log.DebugLevel) if err != nil {
log.Fatalf(err.Error())
} }
log.SetLevel(level)
return nil return nil
} }