@cryptotaxi247 / kubo / commits / e4da27a2a

implemented `ipfs log` command

Henry committed Oct 15, 2014 at 13:34 UTC e4da27a2a5d1c555894619ff68ba397e1f164c7e
2 files changed +22 -6
core/commands/log.go
+1 -1
@@ -13,6 +13,6 @@ func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
13 return err
14 }
15
16 - log.Info("Changed Log of '%q' to '%q'", args[0], args[1])
16 + log.Info("Changed LogLevel of %q to %q", args[0], args[1])
17 return nil
18 }
util/log.go
+21 -5
@@ -30,21 +30,21 @@ func SetupLogging() {
30 logging.SetBackend(backend)
31 logging.SetFormatter(logging.MustStringFormatter(LogFormat))
32
33 - // always prnt critical and error?
33 + // always print critical and error?
34 SetAllLoggers(logging.CRITICAL)
35 SetAllLoggers(logging.ERROR)
36
37 if logenv := os.Getenv("IPFS_LOGGING"); logenv != "" {
38 lvl, err := logging.LogLevel(logenv)
39 if err != nil {
40 - log.Error("invalid logging level: %s\n", logenv)
40 + log.Error("logging.LogLevel() Error: %q\n", err)
41 } else {
42 SetAllLoggers(lvl)
43 }
44 }
45
46 if GetenvBool("IPFS_DEBUG") {
47 - log.Debug("enabling debug printing")
47 + log.Info("enabling debug printing")
48 Debug = true
49 SetAllLoggers(logging.DEBUG)
50 }
@@ -56,7 +56,7 @@ func SetAllLoggers(lvl logging.Level) {
56 logging.SetLevel(lvl, "")
57 for n, log := range loggers {
58 logging.SetLevel(lvl, n)
59 - log.Debug("setting logger: %s to %v", n, lvl)
59 + log.Notice("setting logger: %q to %v", n, lvl)
60 }
61 }
62
@@ -68,11 +68,27 @@ func Logger(name string) *logging.Logger {
68 }
69
70 // SetLogLevel changes the log level of a specific subsystem
71 +// name=="*" changes all subsystems
72 func SetLogLevel(name, level string) error {
73 + lvl, err := logging.LogLevel(level)
74 + if err != nil {
75 + return err
76 + }
77 +
78 + // wildcard, change all
79 + if name == "*" {
80 + SetAllLoggers(lvl)
81 + return nil
82 + }
83 +
84 + // Check if we have a logger by that name
85 + // logging.SetLevel() can't tell us...
86 _, ok := loggers[name]
87 if !ok {
88 return ErrNoSuchLogger
89 }
90
77 - return ErrNotImplemented
91 + logging.SetLevel(lvl, name)
92 +
93 + return nil
94 }