This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters