提交 3455846b 作者: Henry

add log command

上级 c98b0e83
......@@ -63,6 +63,7 @@ Use "ipfs help <command>" for more information about a command.
cmdIpfsBootstrap,
cmdIpfsDiag,
cmdIpfsBlock,
cmdIpfsLog,
},
Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
}
......
package main
import (
flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
)
var cmdIpfsLog = &commander.Command{
UsageLine: "log",
Short: "switch logging levels of the daemon",
Long: `ipfs log - manipulate raw ipfs blocks
ipfs log dht error - log error messages from the dht subsystem
ipfs log merkledag debug - print debug output from the merkledag subsystem
ipfs block is a utility command used to change the logging output of a running daemon.`,
Run: logCmd,
Flag: *flag.NewFlagSet("ipfs-log", flag.ExitOnError),
}
var logCmd = makeCommand(command{
name: "log",
args: 2,
flags: nil,
online: true,
cmdFn: commands.Log,
})
package commands
import (
"io"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
)
// Log changes the log level of a subsystem
func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
if err := u.SetLogLevel(args[0], args[1]); err != nil {
return err
}
log.Info("Changed Log of '%q' to '%q'", args[0], args[1])
return nil
}
......@@ -137,6 +137,8 @@ func (dl *DaemonListener) handleConnection(conn manet.Conn) {
err = commands.BlockGet(dl.node, command.Args, command.Opts, conn)
case "blockPut":
err = commands.BlockPut(dl.node, command.Args, command.Opts, conn)
case "log":
err = commands.Log(dl.node, command.Args, command.Opts, conn)
default:
err = fmt.Errorf("Invalid Command: '%s'", command.Command)
}
......
......@@ -60,9 +60,19 @@ func SetAllLoggers(lvl logging.Level) {
}
}
// Logger retrieves a particular logger + initializes it at a particular level
// Logger retrieves a particular logger
func Logger(name string) *logging.Logger {
log := logging.MustGetLogger(name)
loggers[name] = log
return log
}
// SetLogLevel changes the log level of a specific subsystem
func SetLogLevel(name, level string) error {
_, ok := loggers[name]
if !ok {
return ErrNoSuchLogger
}
return ErrNotImplemented
}
......@@ -33,6 +33,9 @@ var ErrSearchIncomplete = errors.New("Error: Search Incomplete.")
// ErrNotFound is returned when a search fails to find anything
var ErrNotFound = ds.ErrNotFound
// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
var ErrNoSuchLogger = errors.New("Error: No such logger")
// TildeExpansion expands a filename, which may begin with a tilde.
func TildeExpansion(filename string) (string, error) {
return homedir.Expand(filename)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论