/
log_level.go
44 lines (37 loc) 路 1.1 KB
/
log_level.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
package nodecmd
import (
"context"
"strings"
"github.com/ava-labs/avalanchego/api/admin"
"github.com/ava-labs/coreth/plugin/evm"
ethlog "github.com/ethereum/go-ethereum/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func newLogLevelCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "log-level level chain-name",
Short: "Set the log level for a running node and blockchain (X,P,C)",
Long: `Set the log level for a running node (DEBUG, INFO, ERROR) and for a specific chain (X, P, C, BlkchainID)`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return setLoggerLevel(strings.ToLower(args[0]), strings.ToUpper(args[1]))
},
}
return cmd
}
func setLoggerLevel(level string, chainName string) error {
ctx := context.Background()
uri := viper.GetString("node-url")
if chainName == "X" || chainName == "P" {
c := admin.NewClient(uri)
_, err := c.SetLoggerLevel(ctx, chainName, level, level)
return err
}
lvl, err := ethlog.LvlFromString(level)
if err != nil {
return err
}
c := evm.NewClient(uri, chainName)
return c.SetLogLevel(ctx, lvl)
}