Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Opt: add log cmd (#139)
Browse files Browse the repository at this point in the history
Co-authored-by: 一页素书 <2931107265@qq.com>
  • Loading branch information
diwufeiwen and ta0li authored Nov 17, 2021
1 parent ac21877 commit 80093f1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
105 changes: 105 additions & 0 deletions app/venus-sealer/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package main

import (
"fmt"

"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus-sealer/api"
)

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 {
storageAPI, closer, err := api.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := api.ReqContext(cctx)

systems, err := storageAPI.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",
ArgsUsage: "[level]",
Description: `Set the log level for logging systems:
The system flag can be specified multiple times.
eg) log set-level --system chain --system chainxchg 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
GOLOG_OUTPUT - Specify whether to output to file, stderr, stdout or a combination, i.e. file+stderr
`,
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "system",
Usage: "limit to log system",
Value: &cli.StringSlice{},
},
},
Action: func(cctx *cli.Context) error {
storageAPI, closer, err := api.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := api.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 = storageAPI.LogList(ctx)
if err != nil {
return err
}
}

for _, system := range systems {
if err := storageAPI.LogSetLevel(ctx, system, cctx.Args().First()); err != nil {
return xerrors.Errorf("setting log level on %s: %v", system, err)
}
}

return nil
},
}
2 changes: 1 addition & 1 deletion app/venus-sealer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
sealer.SetupLogLevels()

local := []*cli.Command{
initCmd, runCmd, pprofCmd, sectorsCmd, dealsCmd, actorCmd, infoCmd, sealingCmd, storageCmd, messagerCmds, provingCmd, stopCmd, versionCmd, tokenCmd,
logCmd, initCmd, runCmd, pprofCmd, sectorsCmd, dealsCmd, actorCmd, infoCmd, sealingCmd, storageCmd, messagerCmds, provingCmd, stopCmd, versionCmd, tokenCmd,
}
jaeger := tracing.SetupJaegerTracing("venus-sealer")
defer func() {
Expand Down

0 comments on commit 80093f1

Please sign in to comment.