Skip to content

Commit

Permalink
Support disabling of file logging (--nologfiles)
Browse files Browse the repository at this point in the history
  • Loading branch information
supertypo committed Jul 11, 2023
1 parent 1413fdb commit 51aa555
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ConfigFlags struct {
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
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"`
config.NetworkFlags
}

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

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

return activeConfig, nil
}
Expand Down
26 changes: 14 additions & 12 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ var (
spawn = panics.GoroutineWrapperFunc(log)
)

func initLog(logFile, errLogFile string) {
err := backendLog.AddLogFile(logFile, logger.LevelTrace)
func initLog(noLogFiles bool, logFile, errLogFile string) {
err := backendLog.AddLogWriter(os.Stdout, logger.LevelInfo)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", logFile, logger.LevelTrace, err)
os.Exit(1)
}
err = backendLog.AddLogFile(errLogFile, logger.LevelWarn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", errLogFile, logger.LevelWarn, err)
fmt.Fprintf(os.Stderr, "Error adding stdout to the loggerfor level %s: %s", logger.LevelWarn, err)
os.Exit(1)
}

err = backendLog.AddLogWriter(os.Stdout, logger.LevelInfo)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding stdout to the loggerfor level %s: %s", logger.LevelWarn, err)
os.Exit(1)
if !noLogFiles {
err = backendLog.AddLogFile(logFile, logger.LevelTrace)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", logFile, logger.LevelTrace, err)
os.Exit(1)
}
err = backendLog.AddLogFile(errLogFile, logger.LevelWarn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", errLogFile, logger.LevelWarn, err)
os.Exit(1)
}
}

err = backendLog.Run()
Expand Down

0 comments on commit 51aa555

Please sign in to comment.