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