Skip to content

Commit

Permalink
fix(2/log) use 'all' as the specifier to set all log levels
Browse files Browse the repository at this point in the history
fixes #322

cc @mappum

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
  • Loading branch information
Brian Tiger Chow committed Nov 13, 2014
1 parent 597c957 commit 955b792
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions core/commands2/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
u "github.com/jbenet/go-ipfs/util"
)

// Golang os.Args overrides * and replaces the character argument with
// an array which includes every file in the user's CWD. As a
// workaround, we use 'all' instead. The util library still uses * so
// we convert it at this step.
var logAllKeyword = "all"

var logCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Change the logging level",
Expand All @@ -17,16 +23,29 @@ output of a running daemon.
},

Arguments: []cmds.Argument{
cmds.StringArg("subsystem", true, false, "the subsystem logging identifier. Use * for all subsystems."),
// TODO use a different keyword for 'all' because all can theoretically
// clash with a subsystem name
cmds.StringArg("subsystem", true, false, fmt.Sprintf("the subsystem logging identifier. Use '%s' for all subsystems.", logAllKeyword)),
cmds.StringArg("level", true, false, "one of: debug, info, notice, warning, error, critical"),
},
Run: func(req cmds.Request) (interface{}, error) {

args := req.Arguments()
if err := u.SetLogLevel(args[0].(string), args[1].(string)); err != nil {
subsystem, ok1 := args[0].(string)
level, ok2 := args[1].(string)
if !ok1 || !ok2 {
return nil, u.ErrCast()
}

if subsystem == logAllKeyword {
subsystem = "*"
}

if err := u.SetLogLevel(subsystem, level); err != nil {
return nil, err
}

s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1])
s := fmt.Sprintf("Changed log level of '%s' to '%s'", subsystem, level)
log.Info(s)
return &MessageOutput{s}, nil
},
Expand Down

0 comments on commit 955b792

Please sign in to comment.