allow disable file logging (#8884)

allows the disabling of file logging using the new flag
`--log.dir.disable`



NOTE: diagnostics tool logs WILL NOT function if this is set.
This commit is contained in:
a 2023-12-03 22:11:11 -06:00 committed by GitHub
parent 2991a6b645
commit b376d3cabf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 22 deletions

View File

@ -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,

View File

@ -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
}