Skip to content

Commit

Permalink
cmd: switch to --log and --verbose
Browse files Browse the repository at this point in the history
Add custom logging levels, defaulting to the logging level of warning.
This makes the output much less spammy.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
  • Loading branch information
cyphar committed Feb 6, 2017
1 parent 8b73b49 commit fcf30c7
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions cmd/umoci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ const (
)

func main() {
// TODO: Add some form of --verbose flag.
log.SetHandler(logcli.New(os.Stderr))

app := cli.NewApp()
app.Name = "umoci"
app.Usage = usage
Expand All @@ -69,14 +66,34 @@ func main() {

app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "set log level to debug",
Name: "verbose",
Usage: "alias for --log=info",
},
cli.StringFlag{
Name: "log",
Usage: "set the log level (debug, info, [warn], error, fatal)",
Value: "warn",
},
}

app.Before = func(ctx *cli.Context) error {
if ctx.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
log.SetHandler(logcli.New(os.Stderr))

if ctx.GlobalBool("verbose") {
if ctx.GlobalIsSet("log") {
return errors.New("--log=* and --verbose are mutually exclusive")
}
ctx.GlobalSet("log", "info")
}

level, err := log.ParseLevel(ctx.GlobalString("log"))
if err != nil {
return errors.Wrap(err, "parsing log level")
}

log.SetLevel(level)

if level == log.DebugLevel {
errors.Debug(true)
}
return nil
Expand Down

0 comments on commit fcf30c7

Please sign in to comment.