Skip to content

Commit

Permalink
allow disable file logging (erigontech#8884)
Browse files Browse the repository at this point in the history
allows the disabling of file logging using the new flag
`--log.dir.disable`



NOTE: diagnostics tool logs WILL NOT function if this is set.
  • Loading branch information
elee1766 authored Dec 4, 2023
1 parent 2991a6b commit b376d3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
6 changes: 5 additions & 1 deletion turbo/logging/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -56,6 +59,7 @@ var Flags = []cli.Flag{
&LogDirJsonFlag,
&LogVerbosityFlag,
&LogConsoleVerbosityFlag,
&LogDirDisableFlag,
&LogDirPathFlag,
&LogDirPrefixFlag,
&LogDirVerbosityFlag,
Expand Down
51 changes: 30 additions & 21 deletions turbo/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,27 @@ 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()
} else {
logger = log.New()
}

if logDirPrefix := ctx.String(LogDirPrefixFlag.Name); len(logDirPrefix) > 0 {
filePrefix = logDirPrefix
}

initSeparatedLogging(logger, filePrefix, dirPath, consoleLevel, dirLevel, consoleJson, dirJson)
return logger
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b376d3c

Please sign in to comment.