Skip to content

Commit bb70977

Browse files
authored
chore: log failure to run CLI command (#12863)
Log failure to run CLI command Prior code only conditionally logged the output when `LOTUS_DEV` env var was present. This doesn't make sense for a number of reasons: * In case of an error starting up `lotus daemon` via systemctl for example the logs would miss the error. One then has to search through system journal to see what happened. * There are no other places that I can find where `LOTUS_DEV` env var is used. The commit that introduced this condition is very old with no clear commit message to shed light into the rationale. For the first reason alone, the changes here remove that condition, and log the message when the logging output is not standard err or out. This way we at least cover the case where lotus is run in a production environment and would avoid partial logging of errors.
1 parent e4ea131 commit bb70977

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cli/helper.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/signal"
99
"syscall"
1010

11+
logging "github.com/ipfs/go-log/v2"
1112
ufcli "github.com/urfave/cli/v2"
1213
)
1314

@@ -46,11 +47,13 @@ func RunApp(app *ufcli.App) {
4647
}()
4748

4849
if err := app.Run(os.Args); err != nil {
49-
if os.Getenv("LOTUS_DEV") != "" {
50-
log.Warnf("%+v", err)
51-
} else {
52-
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err) // nolint:errcheck
50+
if cfg := logging.GetConfig(); !(cfg.Stdout || cfg.Stderr) {
51+
// To avoid printing the error twice while making sure that log file contains the
52+
// error, check the config and only print it if the output isn't stderr or
53+
// stdout.
54+
log.Errorw("Failed to start application", "err", err)
5355
}
56+
_, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
5457
var phe *PrintHelpErr
5558
if errors.As(err, &phe) {
5659
_ = ufcli.ShowCommandHelp(phe.Ctx, phe.Ctx.Command.Name)

0 commit comments

Comments
 (0)