Skip to content

Commit

Permalink
Support setting stdout loglevel (--loglevel)
Browse files Browse the repository at this point in the history
  • Loading branch information
supertypo committed Jul 11, 2023
1 parent 51aa555 commit 68b2e91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ConfigFlags struct {
GRPCListen string `long:"grpclisten" description:"Listen gRPC requests on address:port"`
NetSuffix uint16 `long:"netsuffix" description:"Testnet network suffix number"`
NoLogFiles bool `long:"nologfiles" description:"Disable logging to file"`
LogLevel string `long:"loglevel" description:"Loglevel for stdout (console). Default: Info"`
config.NetworkFlags
}

Expand Down Expand Up @@ -205,7 +206,7 @@ func loadConfig() (*ConfigFlags, error) {
}
}

initLog(activeConfig.NoLogFiles, appLogFile, appErrLogFile)
initLog(activeConfig.NoLogFiles, activeConfig.LogLevel, appLogFile, appErrLogFile)

return activeConfig, nil
}
Expand Down
5 changes: 3 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var (
spawn = panics.GoroutineWrapperFunc(log)
)

func initLog(noLogFiles bool, logFile, errLogFile string) {
err := backendLog.AddLogWriter(os.Stdout, logger.LevelInfo)
func initLog(noLogFiles bool, logLevel, logFile, errLogFile string) {
level, _ := logger.LevelFromString(logLevel)
err := backendLog.AddLogWriter(os.Stdout, level)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding stdout to the loggerfor level %s: %s", logger.LevelWarn, err)
os.Exit(1)
Expand Down

0 comments on commit 68b2e91

Please sign in to comment.