diff --git a/turbo/logging/flags.go b/turbo/logging/flags.go index b7e9e5672..e5bc2887e 100644 --- a/turbo/logging/flags.go +++ b/turbo/logging/flags.go @@ -32,7 +32,10 @@ var ( Usage: "Set the log level for console logs", Value: log.LvlInfo.String(), } - + LogDirDisableFlag = cli.BoolFlag{ + Name: "log.dir.disable", + Usage: "disable disk logging", + } LogDirPathFlag = cli.StringFlag{ Name: "log.dir.path", Usage: "Path to store user and error logs to disk", @@ -56,6 +59,7 @@ var Flags = []cli.Flag{ &LogDirJsonFlag, &LogVerbosityFlag, &LogConsoleVerbosityFlag, + &LogDirDisableFlag, &LogDirPathFlag, &LogDirPrefixFlag, &LogDirVerbosityFlag, diff --git a/turbo/logging/logging.go b/turbo/logging/logging.go index 4fd64ef51..988fa7fb5 100644 --- a/turbo/logging/logging.go +++ b/turbo/logging/logging.go @@ -39,13 +39,20 @@ func SetupLoggerCtx(filePrefix string, ctx *cli.Context, rootHandler bool) log.L dirLevel = log.LvlInfo } - dirPath := ctx.String(LogDirPathFlag.Name) - if dirPath == "" { - datadir := ctx.String("datadir") - if datadir != "" { - dirPath = filepath.Join(datadir, "logs") + dirPath := "" + if !ctx.Bool(LogDirDisableFlag.Name) && dirPath != "/dev/null" { + dirPath = ctx.String(LogDirPathFlag.Name) + if dirPath == "" { + datadir := ctx.String("datadir") + if datadir != "" { + dirPath = filepath.Join(datadir, "logs") + } + } + if logDirPrefix := ctx.String(LogDirPrefixFlag.Name); len(logDirPrefix) > 0 { + filePrefix = logDirPrefix } } + var logger log.Logger if rootHandler { logger = log.Root() @@ -53,10 +60,6 @@ func SetupLoggerCtx(filePrefix string, ctx *cli.Context, rootHandler bool) log.L logger = log.New() } - if logDirPrefix := ctx.String(LogDirPrefixFlag.Name); len(logDirPrefix) > 0 { - filePrefix = logDirPrefix - } - initSeparatedLogging(logger, filePrefix, dirPath, consoleLevel, dirLevel, consoleJson, dirJson) return logger } @@ -98,19 +101,25 @@ func SetupLoggerCmd(filePrefix string, cmd *cobra.Command) log.Logger { dirLevel = log.LvlInfo } - dirPath := cmd.Flags().Lookup(LogDirPathFlag.Name).Value.String() - if dirPath == "" { - datadirFlag := cmd.Flags().Lookup("datadir") - if datadirFlag != nil { - datadir := datadirFlag.Value.String() - if datadir != "" { - dirPath = filepath.Join(datadir, "logs") + dirPath := "" + disableFileLogging, err := cmd.Flags().GetBool(LogDirDisableFlag.Name) + if err != nil { + disableFileLogging = false + } + if !disableFileLogging && dirPath != "/dev/null" { + dirPath = cmd.Flags().Lookup(LogDirPathFlag.Name).Value.String() + if dirPath == "" { + datadirFlag := cmd.Flags().Lookup("datadir") + if datadirFlag != nil { + datadir := datadirFlag.Value.String() + if datadir != "" { + dirPath = filepath.Join(datadir, "logs") + } } } - } - - if logDirPrefix := cmd.Flags().Lookup(LogDirPrefixFlag.Name).Value.String(); len(logDirPrefix) > 0 { - filePrefix = logDirPrefix + if logDirPrefix := cmd.Flags().Lookup(LogDirPrefixFlag.Name).Value.String(); len(logDirPrefix) > 0 { + filePrefix = logDirPrefix + } } initSeparatedLogging(log.Root(), filePrefix, dirPath, consoleLevel, dirLevel, consoleJson, dirJson) @@ -177,7 +186,7 @@ func initSeparatedLogging( logger.SetHandler(consoleHandler) if len(dirPath) == 0 { - logger.Warn("no log dir set, console logging only") + logger.Info("console logging only") return }