@cryptotaxi247 / kubo / commits / 3455846b3

add log command

Henry committed Oct 15, 2014 at 13:12 UTC 3455846b3503f5c6b75a0df8f398cefdf7160908
6 files changed +64 -1
cmd/ipfs/ipfs.go
+1
@@ -63,6 +63,7 @@ Use "ipfs help <command>" for more information about a command.
63 cmdIpfsBootstrap,
64 cmdIpfsDiag,
65 cmdIpfsBlock,
66 + cmdIpfsLog,
67 },
68 Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
69 }
cmd/ipfs/log.go new
+29
@@ -0,0 +1,29 @@
1 +package main
2 +
3 +import (
4 + flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5 + commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6 + "github.com/jbenet/go-ipfs/core/commands"
7 +)
8 +
9 +var cmdIpfsLog = &commander.Command{
10 + UsageLine: "log",
11 + Short: "switch logging levels of the daemon",
12 + Long: `ipfs log - manipulate raw ipfs blocks
13 +
14 + ipfs log dht error - log error messages from the dht subsystem
15 + ipfs log merkledag debug - print debug output from the merkledag subsystem
16 +
17 +
18 +ipfs block is a utility command used to change the logging output of a running daemon.`,
19 + Run: logCmd,
20 + Flag: *flag.NewFlagSet("ipfs-log", flag.ExitOnError),
21 +}
22 +
23 +var logCmd = makeCommand(command{
24 + name: "log",
25 + args: 2,
26 + flags: nil,
27 + online: true,
28 + cmdFn: commands.Log,
29 +})
core/commands/log.go new
+18
@@ -0,0 +1,18 @@
1 +package commands
2 +
3 +import (
4 + "io"
5 +
6 + "github.com/jbenet/go-ipfs/core"
7 + u "github.com/jbenet/go-ipfs/util"
8 +)
9 +
10 +// Log changes the log level of a subsystem
11 +func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12 + if err := u.SetLogLevel(args[0], args[1]); err != nil {
13 + return err
14 + }
15 +
16 + log.Info("Changed Log of '%q' to '%q'", args[0], args[1])
17 + return nil
18 +}
daemon/daemon.go
+2
@@ -137,6 +137,8 @@ func (dl *DaemonListener) handleConnection(conn manet.Conn) {
137 err = commands.BlockGet(dl.node, command.Args, command.Opts, conn)
138 case "blockPut":
139 err = commands.BlockPut(dl.node, command.Args, command.Opts, conn)
140 + case "log":
141 + err = commands.Log(dl.node, command.Args, command.Opts, conn)
142 default:
143 err = fmt.Errorf("Invalid Command: '%s'", command.Command)
144 }
util/log.go
+11 -1
@@ -60,9 +60,19 @@ func SetAllLoggers(lvl logging.Level) {
60 }
61 }
62
63 -// Logger retrieves a particular logger + initializes it at a particular level
63 +// Logger retrieves a particular logger
64 func Logger(name string) *logging.Logger {
65 log := logging.MustGetLogger(name)
66 loggers[name] = log
67 return log
68 }
69 +
70 +// SetLogLevel changes the log level of a specific subsystem
71 +func SetLogLevel(name, level string) error {
72 + _, ok := loggers[name]
73 + if !ok {
74 + return ErrNoSuchLogger
75 + }
76 +
77 + return ErrNotImplemented
78 +}
util/util.go
+3
@@ -33,6 +33,9 @@ var ErrSearchIncomplete = errors.New("Error: Search Incomplete.")
33 // ErrNotFound is returned when a search fails to find anything
34 var ErrNotFound = ds.ErrNotFound
35
36 +// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
37 +var ErrNoSuchLogger = errors.New("Error: No such logger")
38 +
39 // TildeExpansion expands a filename, which may begin with a tilde.
40 func TildeExpansion(filename string) (string, error) {
41 return homedir.Expand(filename)