-
Notifications
You must be signed in to change notification settings - Fork 467
/
Copy pathlog.go
112 lines (95 loc) · 2.54 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package cmd
import (
"fmt"
"strings"
cmds "github.com/ipfs/go-ipfs-cmds"
logging "github.com/ipfs/go-log/v2"
)
var logCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Interact with the daemon subsystems log output.",
ShortDescription: `
'venus log' contains utility commands to affect the subsystems logging
output of a running daemon.
`,
},
Subcommands: map[string]*cmds.Command{
"set-level": logLevelCmd,
"list": logLsCmd,
"tail": logTailCmd,
},
}
var logTailCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Read subsystems log output.",
ShortDescription: `
Outputs subsystems log output as it is generated.
`,
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
r := logging.NewPipeReader()
go func() {
defer r.Close() // nolint: errcheck
<-req.Context.Done()
}()
return re.Emit(r)
},
}
var logLevelCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Set the logging level.",
ShortDescription: `Set the log level for logging systems:
The system flag can be specified multiple times.
eg) log set-level --system chain --system pubsub debug
Available Levels:
debug
info
warn
error
fatal
panic
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("set-level", true, false, `The log level, with 'debug' the most verbose and 'panic' the least verbose.
One of: debug, info, warning, error, fatal, panic.
`),
},
Options: []cmds.Option{
cmds.StringsOption("system", "The system logging identifier"),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
level := strings.ToLower(req.Arguments[0])
var s string
if system, ok := req.Options["system"].([]string); ok {
for _, v := range system {
if err := logging.SetLogLevel(v, level); err != nil {
return err
}
}
s = fmt.Sprintf("Set log level of '%s' to '%s'", strings.Join(system, ","), level)
} else {
lvl, err := logging.LevelFromString(level)
if err != nil {
return err
}
logging.SetAllLoggers(lvl)
s = fmt.Sprintf("Set log level of all subsystems to: %s", level)
}
return cmds.EmitOnce(res, s)
},
Type: string(""),
}
var logLsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List the logging subsystems.",
ShortDescription: `
'venus log list' is a utility command used to list the logging
subsystems of a running daemon.
`,
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
return cmds.EmitOnce(res, logging.GetSubsystems())
},
Type: []string{},
}