2020-02-15 05:49:54 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-02-15 05:49:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var logCmd = &cli.Command{
|
|
|
|
Name: "log",
|
|
|
|
Usage: "Manage logging",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
logList,
|
|
|
|
logSetLevel,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var logList = &cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "List log systems",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
systems, err := api.LogList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, system := range systems {
|
|
|
|
fmt.Println(system)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var logSetLevel = &cli.Command{
|
|
|
|
Name: "set-level",
|
|
|
|
Usage: "Set log level",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[level]",
|
2020-02-15 05:49:54 +00:00
|
|
|
Description: `Set the log level for logging systems:
|
|
|
|
|
|
|
|
The system flag can be specified multiple times.
|
|
|
|
|
|
|
|
eg) log set-level --system chain --system blocksync debug
|
|
|
|
|
|
|
|
Available Levels:
|
|
|
|
debug
|
|
|
|
info
|
|
|
|
warn
|
|
|
|
error
|
|
|
|
|
|
|
|
Environment Variables:
|
|
|
|
GOLOG_LOG_LEVEL - Default log level for all log systems
|
|
|
|
GOLOG_LOG_FMT - Change output log format (json, nocolor)
|
|
|
|
GOLOG_FILE - Write logs to file in addition to stderr
|
|
|
|
`,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "system",
|
|
|
|
Usage: "limit to log system",
|
|
|
|
Value: &cli.StringSlice{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
if !cctx.Args().Present() {
|
|
|
|
return fmt.Errorf("level is required")
|
|
|
|
}
|
|
|
|
|
|
|
|
systems := cctx.StringSlice("system")
|
|
|
|
if len(systems) == 0 {
|
|
|
|
var err error
|
|
|
|
systems, err = api.LogList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, system := range systems {
|
|
|
|
if err := api.LogSetLevel(ctx, system, cctx.Args().First()); err != nil {
|
|
|
|
return xerrors.Errorf("setting log level on %s: %w", system, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|