fix(2/log) use 'all' as the specifier to set all log levels
fixes #322 cc @mappum License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 12, 2014 at 23:27 UTC
131c15e924447a3dbe42a446f2faf70ebdc66da2
1 file changed
+22
-3
core/commands2/log.go
+22
-3
@@ -7,6 +7,12 @@ import (
7
u "github.com/jbenet/go-ipfs/util"
8
)
9
10
+// Golang os.Args overrides * and replaces the character argument with
11
+// an array which includes every file in the user's CWD. As a
12
+// workaround, we use 'all' instead. The util library still uses * so
13
+// we convert it at this step.
14
+var logAllKeyword = "all"
15
+
16
var logCmd = &cmds.Command{
17
Helptext: cmds.HelpText{
18
Tagline: "Change the logging level",
@@ -17,16 +23,29 @@ output of a running daemon.
23
},
24
25
Arguments: []cmds.Argument{
20
- cmds.StringArg("subsystem", true, false, "the subsystem logging identifier. Use * for all subsystems."),
26
+ // TODO use a different keyword for 'all' because all can theoretically
27
+ // clash with a subsystem name
28
+ cmds.StringArg("subsystem", true, false, fmt.Sprintf("the subsystem logging identifier. Use '%s' for all subsystems.", logAllKeyword)),
29
cmds.StringArg("level", true, false, "one of: debug, info, notice, warning, error, critical"),
30
},
31
Run: func(req cmds.Request) (interface{}, error) {
32
+
33
args := req.Arguments()
25
- if err := u.SetLogLevel(args[0].(string), args[1].(string)); err != nil {
34
+ subsystem, ok1 := args[0].(string)
35
+ level, ok2 := args[1].(string)
36
+ if !ok1 || !ok2 {
37
+ return nil, u.ErrCast()
38
+ }
39
+
40
+ if subsystem == logAllKeyword {
41
+ subsystem = "*"
42
+ }
43
+
44
+ if err := u.SetLogLevel(subsystem, level); err != nil {
45
return nil, err
46
}
47
29
- s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1])
48
+ s := fmt.Sprintf("Changed log level of '%s' to '%s'", subsystem, level)
49
log.Info(s)
50
return &MessageOutput{s}, nil
51
},