提交 e4da27a2 作者: Henry

implemented `ipfs log` command

上级 3455846b
...@@ -13,6 +13,6 @@ func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr ...@@ -13,6 +13,6 @@ func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
return err return err
} }
log.Info("Changed Log of '%q' to '%q'", args[0], args[1]) log.Info("Changed LogLevel of %q to %q", args[0], args[1])
return nil return nil
} }
...@@ -30,21 +30,21 @@ func SetupLogging() { ...@@ -30,21 +30,21 @@ func SetupLogging() {
logging.SetBackend(backend) logging.SetBackend(backend)
logging.SetFormatter(logging.MustStringFormatter(LogFormat)) logging.SetFormatter(logging.MustStringFormatter(LogFormat))
// always prnt critical and error? // always print critical and error?
SetAllLoggers(logging.CRITICAL) SetAllLoggers(logging.CRITICAL)
SetAllLoggers(logging.ERROR) SetAllLoggers(logging.ERROR)
if logenv := os.Getenv("IPFS_LOGGING"); logenv != "" { if logenv := os.Getenv("IPFS_LOGGING"); logenv != "" {
lvl, err := logging.LogLevel(logenv) lvl, err := logging.LogLevel(logenv)
if err != nil { if err != nil {
log.Error("invalid logging level: %s\n", logenv) log.Error("logging.LogLevel() Error: %q\n", err)
} else { } else {
SetAllLoggers(lvl) SetAllLoggers(lvl)
} }
} }
if GetenvBool("IPFS_DEBUG") { if GetenvBool("IPFS_DEBUG") {
log.Debug("enabling debug printing") log.Info("enabling debug printing")
Debug = true Debug = true
SetAllLoggers(logging.DEBUG) SetAllLoggers(logging.DEBUG)
} }
...@@ -56,7 +56,7 @@ func SetAllLoggers(lvl logging.Level) { ...@@ -56,7 +56,7 @@ func SetAllLoggers(lvl logging.Level) {
logging.SetLevel(lvl, "") logging.SetLevel(lvl, "")
for n, log := range loggers { for n, log := range loggers {
logging.SetLevel(lvl, n) logging.SetLevel(lvl, n)
log.Debug("setting logger: %s to %v", n, lvl) log.Notice("setting logger: %q to %v", n, lvl)
} }
} }
...@@ -68,11 +68,27 @@ func Logger(name string) *logging.Logger { ...@@ -68,11 +68,27 @@ func Logger(name string) *logging.Logger {
} }
// SetLogLevel changes the log level of a specific subsystem // SetLogLevel changes the log level of a specific subsystem
// name=="*" changes all subsystems
func SetLogLevel(name, level string) error { func SetLogLevel(name, level string) error {
lvl, err := logging.LogLevel(level)
if err != nil {
return err
}
// wildcard, change all
if name == "*" {
SetAllLoggers(lvl)
return nil
}
// Check if we have a logger by that name
// logging.SetLevel() can't tell us...
_, ok := loggers[name] _, ok := loggers[name]
if !ok { if !ok {
return ErrNoSuchLogger return ErrNoSuchLogger
} }
return ErrNotImplemented logging.SetLevel(lvl, name)
return nil
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论