added --log.dir.prefix flag (#7714)

This request adds an additional logging flag to change the name of the
logfiles produced by erigon to be prefixed by a name other than
'erigon'.

This allows multiple nodes to log to the same directory without
overwriting each others files. It is requires so that the devnet when
running can maintain all of its log files in a single consolidated
directory which survives devnet restarts.

---------

Co-authored-by: Mark Holt <mark@distributed.vision>
This commit is contained in:
Mark Holt 2023-06-12 15:30:05 +01:00 committed by GitHub
parent 5c0c9fdff9
commit e99269ebce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 1 deletions

View File

@ -125,6 +125,7 @@ _Flags:_
- `log.json`
- `log.console.json` (alias for `log.json`)
- `log.dir.path`
- `log.dir.prefix`
- `log.dir.verbosity`
- `log.dir.json`
@ -140,7 +141,7 @@ int value specifying the highest output log level:
LvlTrace = 5
```
To set an output dir for logs to be collected on disk, please set `--log.dir.path`. The flag `--log.dir.verbosity` is
To set an output dir for logs to be collected on disk, please set `--log.dir.path` If you want to change the filename prodiced from `erigon` you should also set the `--log.dir.prefix` flag to an alternate name. The flag `--log.dir.verbosity` is
also available to control the verbosity of this logging, with the same int value as above, or the string value e.g. '
debug' or 'info'. Default verbosity is 'debug' (4), for disk logging.

View File

@ -18,6 +18,7 @@ How to run Erigon in a single process (all parts of the system run as one).
--ws \
--http.api=eth,debug,net,trace,web3,erigon \
--log.dir.path=/desired/path/to/logs
--log.dir.prefix=filename
```
## Notes

View File

@ -38,6 +38,11 @@ var (
Usage: "Path to store user and error logs to disk",
}
LogDirPrefixFlag = cli.StringFlag{
Name: "log.dir.prefix",
Usage: "The file name prefix for logs stored to disk",
}
LogDirVerbosityFlag = cli.StringFlag{
Name: "log.dir.verbosity",
Usage: "Set the log verbosity for logs stored to disk",
@ -52,5 +57,6 @@ var Flags = []cli.Flag{
&LogVerbosityFlag,
&LogConsoleVerbosityFlag,
&LogDirPathFlag,
&LogDirPrefixFlag,
&LogDirVerbosityFlag,
}

View File

@ -52,6 +52,11 @@ func SetupLoggerCtx(filePrefix string, ctx *cli.Context, rootHandler bool) log.L
} 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
}
@ -100,6 +105,11 @@ func SetupLoggerCmd(filePrefix string, cmd *cobra.Command) log.Logger {
dirPath = filepath.Join(datadir, "logs")
}
}
if logDirPrefix := cmd.Flags().Lookup(LogDirPrefixFlag.Name).Value.String(); len(logDirPrefix) > 0 {
filePrefix = logDirPrefix
}
initSeparatedLogging(log.Root(), filePrefix, dirPath, consoleLevel, dirLevel, consoleJson, dirJson)
return log.Root()
}
@ -110,6 +120,7 @@ func SetupLogger(filePrefix string) log.Logger {
var logConsoleVerbosity = flag.String(LogConsoleVerbosityFlag.Name, "", LogConsoleVerbosityFlag.Usage)
var logDirVerbosity = flag.String(LogDirVerbosityFlag.Name, "", LogDirVerbosityFlag.Usage)
var logDirPath = flag.String(LogDirPathFlag.Name, "", LogDirPathFlag.Usage)
var logDirPrefix = flag.String(LogDirPrefixFlag.Name, "", LogDirPrefixFlag.Usage)
var logVerbosity = flag.String(LogVerbosityFlag.Name, "", LogVerbosityFlag.Usage)
var logConsoleJson = flag.Bool(LogConsoleJsonFlag.Name, false, LogConsoleJsonFlag.Usage)
var logJson = flag.Bool(LogJsonFlag.Name, false, LogJsonFlag.Usage)
@ -133,6 +144,10 @@ func SetupLogger(filePrefix string) log.Logger {
dirLevel = log.LvlInfo
}
if logDirPrefix != nil && len(*logDirPrefix) > 0 {
filePrefix = *logDirPrefix
}
initSeparatedLogging(log.Root(), filePrefix, *logDirPath, consoleLevel, dirLevel, consoleJson, *dirJson)
return log.Root()
}