log.go 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
package commands

import (
	"fmt"

	cmds "github.com/jbenet/go-ipfs/commands"
	u "github.com/jbenet/go-ipfs/util"
)

var logCmd = &cmds.Command{
	Arguments: []cmds.Argument{
		cmds.Argument{"subsystem", cmds.ArgString, true, false},
		cmds.Argument{"level", cmds.ArgString, true, false},
	},
Brian Tiger Chow's avatar
Brian Tiger Chow committed
15 16 17 18 19 20 21 22 23
	// TODO UsageLine: "log <name> <level> ",
	// TODO Short:     "switch logging levels of a running daemon",
	Help: `ipfs log <subsystem> <level> - switch logging levels of a running daemon

   <subsystem> is a the subsystem logging identifier. Use * for all subsystems.
   <level> is one of: debug, info, notice, warning, error, critical

ipfs log is a utility command used to change the logging output of a running daemon.
`,
24 25 26 27 28 29 30 31
	Run: func(res cmds.Response, req cmds.Request) {
		args := req.Arguments()
		if err := u.SetLogLevel(args[0].(string), args[1].(string)); err != nil {
			res.SetError(err, cmds.ErrClient)
			return
		}

		s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1])
32
		res.SetOutput(&MessageOutput{s})
33
	},
34 35 36 37
	Marshallers: map[cmds.EncodingType]cmds.Marshaller{
		cmds.Text: MessageTextMarshaller,
	},
	Type: &MessageOutput{},
38
}