From 4c5e5653e48259613a22beaefdf87aa975a42d0d Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Oct 2024 17:42:06 +0200 Subject: [PATCH 1/7] build: rename config.go file to config_prod.go in preparation for adding a shared config.go file. --- build/{config.go => config_prod.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename build/{config.go => config_prod.go} (100%) diff --git a/build/config.go b/build/config_prod.go similarity index 100% rename from build/config.go rename to build/config_prod.go From 0512357c17e37cb7ff79b9ca063f897ed3229067 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Oct 2024 17:50:52 +0200 Subject: [PATCH 2/7] build: dedup logging config Move all shared code to config.go which has no build tags. --- build/config.go | 61 ++++++++++++++++++++++++++++++++++++++ build/config_dev.go | 70 +++++++------------------------------------- build/config_prod.go | 61 ++++++-------------------------------- 3 files changed, 80 insertions(+), 112 deletions(-) create mode 100644 build/config.go diff --git a/build/config.go b/build/config.go new file mode 100644 index 000000000..1cfce7a45 --- /dev/null +++ b/build/config.go @@ -0,0 +1,61 @@ +package build + +import "github.com/btcsuite/btclog/v2" + +const ( + callSiteOff = "off" + callSiteShort = "short" + callSiteLong = "long" +) + +// LogConfig holds logging configuration options. +// +//nolint:lll +type LogConfig struct { + Console *consoleLoggerCfg `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."` + File *LoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` +} + +// LoggerConfig holds options for a particular logger. +// +//nolint:lll +type LoggerConfig struct { + Disable bool `long:"disable" description:"Disable this logger."` + NoTimestamps bool `long:"no-timestamps" description:"Omit timestamps from log lines."` + CallSite string `long:"call-site" description:"Include the call-site of each log line." choice:"off" choice:"short" choice:"long"` +} + +// DefaultLogConfig returns the default logging config options. +func DefaultLogConfig() *LogConfig { + return &LogConfig{ + Console: defaultConsoleLoggerCfg(), + File: &LoggerConfig{ + CallSite: callSiteOff, + }, + } +} + +// HandlerOptions returns the set of btclog.HandlerOptions that the state of the +// config struct translates to. +func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { + opts := []btclog.HandlerOption{ + // The default skip depth used by the logging library is 6 but + // since we wrap the logging handlers with another level of + // abstraction with the handlerSet, we increase the skip depth + // to 7 here. + btclog.WithCallSiteSkipDepth(7), + } + + if cfg.NoTimestamps { + opts = append(opts, btclog.WithNoTimestamp()) + } + + switch cfg.CallSite { + case callSiteShort: + opts = append(opts, btclog.WithCallerFlags(btclog.Lshortfile)) + case callSiteLong: + opts = append(opts, btclog.WithCallerFlags(btclog.Llongfile)) + } + + return opts +} diff --git a/build/config_dev.go b/build/config_dev.go index daa5b1fde..09df7d618 100644 --- a/build/config_dev.go +++ b/build/config_dev.go @@ -17,68 +17,8 @@ const ( faintSeq = "2" esc = '\x1b' csi = string(esc) + "[" - - callSiteOff = "off" - callSiteShort = "short" - callSiteLong = "long" ) -// LogConfig holds logging configuration options. -// -//nolint:lll -type LogConfig struct { - Console *consoleLoggerCfg `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."` - File *LoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` -} - -// DefaultLogConfig returns the default logging config options. -func DefaultLogConfig() *LogConfig { - return &LogConfig{ - Console: &consoleLoggerCfg{ - LoggerConfig: LoggerConfig{ - CallSite: callSiteShort, - }, - }, - File: &LoggerConfig{ - CallSite: callSiteOff, - }, - } -} - -// LoggerConfig holds options for a particular logger. -// -//nolint:lll -type LoggerConfig struct { - Disable bool `long:"disable" description:"Disable this logger."` - NoTimestamps bool `long:"no-timestamps" description:"Omit timestamps from log lines."` - CallSite string `long:"call-site" description:"Include the call-site of each log line." choice:"off" choice:"short" choice:"long"` -} - -// HandlerOptions returns the set of btclog.HandlerOptions that the state of the -// config struct translates to. -func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { - opts := []btclog.HandlerOption{ - // The default skip depth used by the logging library is 6 but - // since we wrap the logging handlers with another level of - // abstraction with the handlerSet, we increase the skip depth - // to 7 here. - btclog.WithCallSiteSkipDepth(7), - } - - if cfg.NoTimestamps { - opts = append(opts, btclog.WithNoTimestamp()) - } - - switch cfg.CallSite { - case callSiteShort: - opts = append(opts, btclog.WithCallerFlags(btclog.Lshortfile)) - case callSiteLong: - opts = append(opts, btclog.WithCallerFlags(btclog.Llongfile)) - } - - return opts -} - // consoleLoggerCfg extends the LoggerConfig struct by adding a Color option // which is only available for a console logger. // @@ -88,6 +28,16 @@ type consoleLoggerCfg struct { Style bool `long:"style" description:"If set, the output will be styled with color and fonts"` } +// defaultConsoleLoggerCfg returns the default consoleLoggerCfg for the dev +// console logger. +func defaultConsoleLoggerCfg() *consoleLoggerCfg { + return &consoleLoggerCfg{ + LoggerConfig: LoggerConfig{ + CallSite: callSiteShort, + }, + } +} + // HandlerOptions returns the set of btclog.HandlerOptions that the state of the // config struct translates to. func (cfg *consoleLoggerCfg) HandlerOptions() []btclog.HandlerOption { diff --git a/build/config_prod.go b/build/config_prod.go index 66a0b3144..67a43f8ac 100644 --- a/build/config_prod.go +++ b/build/config_prod.go @@ -3,63 +3,20 @@ package build -import "github.com/btcsuite/btclog/v2" - -const ( - callSiteOff = "off" - callSiteShort = "short" - callSiteLong = "long" -) - -// LogConfig holds logging configuration options. +// consoleLoggerCfg embeds the LoggerConfig struct along with any extensions +// specific to a production deployment. // //nolint:lll -type LogConfig struct { - Console *LoggerConfig `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."` - File *LoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` +type consoleLoggerCfg struct { + LoggerConfig } -// DefaultLogConfig returns the default logging config options. -func DefaultLogConfig() *LogConfig { - return &LogConfig{ - Console: &LoggerConfig{ - CallSite: callSiteOff, - }, - File: &LoggerConfig{ +// defaultConsoleLoggerCfg returns the default consoleLoggerCfg for the prod +// console logger. +func defaultConsoleLoggerCfg() *consoleLoggerCfg { + return &consoleLoggerCfg{ + LoggerConfig: LoggerConfig{ CallSite: callSiteOff, }, } } - -// LoggerConfig holds options for a particular logger. -// -//nolint:lll -type LoggerConfig struct { - Disable bool `long:"disable" description:"Disable this logger."` - NoTimestamps bool `long:"no-timestamps" description:"Omit timestamps from log lines."` - CallSite string `long:"call-site" description:"Include the call-site of each log line." choice:"off" choice:"short" choice:"long"` -} - -// HandlerOptions returns the set of btclog.HandlerOptions that the state of the -// config struct translates to. -func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { - opts := []btclog.HandlerOption{ - // The default skip depth used by the logging library is 6 but - // since we wrap the logging handlers with another level of - // abstraction with the handlerSet, we increase the skip depth - // to 7 here. - btclog.WithCallSiteSkipDepth(7), - } - if cfg.NoTimestamps { - opts = append(opts, btclog.WithNoTimestamp()) - } - - switch cfg.CallSite { - case callSiteShort: - opts = append(opts, btclog.WithCallerFlags(btclog.Lshortfile)) - case callSiteLong: - opts = append(opts, btclog.WithCallerFlags(btclog.Llongfile)) - } - - return opts -} From 1886d3865be03eb782a535e50db50af163d5da93 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Oct 2024 17:53:24 +0200 Subject: [PATCH 3/7] build: extract File logging options into own struct In preparation for extending LoggerConfig with file specific config. --- build/config.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/build/config.go b/build/config.go index 1cfce7a45..fcb363987 100644 --- a/build/config.go +++ b/build/config.go @@ -13,7 +13,7 @@ const ( //nolint:lll type LogConfig struct { Console *consoleLoggerCfg `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."` - File *LoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` + File *FileLoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` } // LoggerConfig holds options for a particular logger. @@ -29,8 +29,10 @@ type LoggerConfig struct { func DefaultLogConfig() *LogConfig { return &LogConfig{ Console: defaultConsoleLoggerCfg(), - File: &LoggerConfig{ - CallSite: callSiteOff, + File: &FileLoggerConfig{ + LoggerConfig: LoggerConfig{ + CallSite: callSiteOff, + }, }, } } @@ -59,3 +61,8 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { return opts } + +// FileLoggerConfig extends LoggerConfig with specific log file options. +type FileLoggerConfig struct { + LoggerConfig +} From 3adbdbb39afd459c704a6d8e2b1e7d35bf1bde25 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Oct 2024 17:58:23 +0200 Subject: [PATCH 4/7] multi: move logcompressor to logging.file.compressor This is not a breaking change since the logcompressor config option has not been released yet. --- build/config.go | 22 +++++++++++++++++++++- build/log.go | 4 ++-- build/logrotator.go | 2 +- config.go | 11 ++++------- docs/release-notes/release-notes-0.19.0.md | 4 +++- sample-lnd.conf | 9 ++++++--- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/build/config.go b/build/config.go index fcb363987..4a27f072c 100644 --- a/build/config.go +++ b/build/config.go @@ -1,11 +1,17 @@ package build -import "github.com/btcsuite/btclog/v2" +import ( + "fmt" + + "github.com/btcsuite/btclog/v2" +) const ( callSiteOff = "off" callSiteShort = "short" callSiteLong = "long" + + defaultLogCompressor = Gzip ) // LogConfig holds logging configuration options. @@ -16,6 +22,16 @@ type LogConfig struct { File *FileLoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` } +// Validate validates the LogConfig struct values. +func (c *LogConfig) Validate() error { + if !SupportedLogCompressor(c.File.Compressor) { + return fmt.Errorf("invalid log compressor: %v", + c.File.Compressor) + } + + return nil +} + // LoggerConfig holds options for a particular logger. // //nolint:lll @@ -30,6 +46,7 @@ func DefaultLogConfig() *LogConfig { return &LogConfig{ Console: defaultConsoleLoggerCfg(), File: &FileLoggerConfig{ + Compressor: defaultLogCompressor, LoggerConfig: LoggerConfig{ CallSite: callSiteOff, }, @@ -63,6 +80,9 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { } // FileLoggerConfig extends LoggerConfig with specific log file options. +// +//nolint:lll type FileLoggerConfig struct { LoggerConfig + Compressor string `long:"compressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"` } diff --git a/build/log.go b/build/log.go index 568f9f618..37751ab46 100644 --- a/build/log.go +++ b/build/log.go @@ -52,9 +52,9 @@ var logCompressors = map[string]string{ Zstd: "zst", } -// SuportedLogCompressor returns whether or not logCompressor is a supported +// SupportedLogCompressor returns whether or not logCompressor is a supported // compression algorithm for log files. -func SuportedLogCompressor(logCompressor string) bool { +func SupportedLogCompressor(logCompressor string) bool { _, ok := logCompressors[logCompressor] return ok diff --git a/build/logrotator.go b/build/logrotator.go index 2ae105fde..120e3eaab 100644 --- a/build/logrotator.go +++ b/build/logrotator.go @@ -48,7 +48,7 @@ func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string, } // Reject unknown compressors. - if !SuportedLogCompressor(logCompressor) { + if !SupportedLogCompressor(logCompressor) { return fmt.Errorf("unknown log compressor: %v", logCompressor) } diff --git a/config.go b/config.go index c8991cf60..f9192aadc 100644 --- a/config.go +++ b/config.go @@ -59,7 +59,6 @@ const ( defaultLogLevel = "info" defaultLogDirname = "logs" defaultLogFilename = "lnd.log" - defaultLogCompressor = build.Gzip defaultRPCPort = 10009 defaultRESTPort = 8080 defaultPeerPort = 9735 @@ -316,7 +315,6 @@ type Config struct { ReadMacPath string `long:"readonlymacaroonpath" description:"Path to write the read-only macaroon for lnd's RPC and REST services if it doesn't exist"` InvoiceMacPath string `long:"invoicemacaroonpath" description:"Path to the invoice-only macaroon for lnd's RPC and REST services if it doesn't exist"` LogDir string `long:"logdir" description:"Directory to log output."` - LogCompressor string `long:"logcompressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"` MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)"` MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"` AcceptorTimeout time.Duration `long:"acceptortimeout" description:"Time after which an RPCAcceptor will time out and return false if it hasn't yet received a response"` @@ -564,7 +562,6 @@ func DefaultConfig() Config { LetsEncryptDir: defaultLetsEncryptDir, LetsEncryptListen: defaultLetsEncryptListen, LogDir: defaultLogDir, - LogCompressor: defaultLogCompressor, MaxLogFiles: defaultMaxLogFiles, MaxLogFileSize: defaultMaxLogFileSize, AcceptorTimeout: defaultAcceptorTimeout, @@ -1403,9 +1400,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name), ) - if !build.SuportedLogCompressor(cfg.LogCompressor) { - return nil, mkErr("invalid log compressor: %v", - cfg.LogCompressor) + if err := cfg.LogConfig.Validate(); err != nil { + return nil, mkErr("error validating logging config: %w", err) } cfg.SubLogMgr = build.NewSubLoggerManager(build.NewDefaultLogHandlers( @@ -1423,7 +1419,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, } err = cfg.LogRotator.InitLogRotator( filepath.Join(cfg.LogDir, defaultLogFilename), - cfg.LogCompressor, cfg.MaxLogFileSize, cfg.MaxLogFiles, + cfg.LogConfig.File.Compressor, cfg.MaxLogFileSize, + cfg.MaxLogFiles, ) if err != nil { str := "log rotation setup failed: %v" diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index 3b20a054e..5116b4ba8 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -57,7 +57,9 @@ # Improvements ## Functional Updates -* [Allow](https://github.com/lightningnetwork/lnd/pull/9017) the compression of logs during rotation with ZSTD via the `logcompressor` startup argument. +* [Allow](https://github.com/lightningnetwork/lnd/pull/9017) the compression of + logs during rotation with ZSTD via the `logging.file.compressor` startup + argument. * The SCB file now [contains more data][https://github.com/lightningnetwork/lnd/pull/8183] that enable a last resort rescue for certain cases where the peer is no longer diff --git a/sample-lnd.conf b/sample-lnd.conf index eeb6a9d31..b9aee40e5 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -36,9 +36,6 @@ ; Max log file size in MB before it is rotated. ; maxlogfilesize=10 -; Compression algorithm to use when rotating logs. -; logcompressor=gzip - ; Time after which an RPCAcceptor will time out and return false if ; it hasn't yet received a response. ; acceptortimeout=15s @@ -988,6 +985,12 @@ ; Disable logging to the standard LND log file. ; logging.file.disable=false +; Compression algorithm to use when rotating logs. +; Default: +; logging.file.compressor=gzip +; Example: +; logging.file.compressor=zstd + ; Don't add timestamps to logs written to the standard LND log file. ; logging.file.no-timestamps=false From 22c13790dfc548f2441ce2aa014fb4419277cf77 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Oct 2024 18:08:08 +0200 Subject: [PATCH 5/7] build+config: move maxlogfiles and maxfilesize to logger config Add deprecation notices but continue to read both. --- build/config.go | 15 +++++++++++++-- build/logrotator.go | 14 +++++++------- config.go | 35 +++++++++++++++++++++++++++-------- sample-lnd.conf | 12 +++++++++++- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/build/config.go b/build/config.go index 4a27f072c..e26168f80 100644 --- a/build/config.go +++ b/build/config.go @@ -12,6 +12,13 @@ const ( callSiteLong = "long" defaultLogCompressor = Gzip + + // DefaultMaxLogFiles is the default maximum number of log files to + // keep. + DefaultMaxLogFiles = 3 + + // DefaultMaxLogFileSize is the default maximum log file size in MB. + DefaultMaxLogFileSize = 10 ) // LogConfig holds logging configuration options. @@ -46,7 +53,9 @@ func DefaultLogConfig() *LogConfig { return &LogConfig{ Console: defaultConsoleLoggerCfg(), File: &FileLoggerConfig{ - Compressor: defaultLogCompressor, + Compressor: defaultLogCompressor, + MaxLogFiles: DefaultMaxLogFiles, + MaxLogFileSize: DefaultMaxLogFileSize, LoggerConfig: LoggerConfig{ CallSite: callSiteOff, }, @@ -84,5 +93,7 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { //nolint:lll type FileLoggerConfig struct { LoggerConfig - Compressor string `long:"compressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"` + Compressor string `long:"compressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"` + MaxLogFiles int `long:"max-files" description:"Maximum logfiles to keep (0 for no rotation)"` + MaxLogFileSize int `long:"max-file-size" description:"Maximum logfile size in MB"` } diff --git a/build/logrotator.go b/build/logrotator.go index 120e3eaab..b9b16654c 100644 --- a/build/logrotator.go +++ b/build/logrotator.go @@ -31,8 +31,8 @@ func NewRotatingLogWriter() *RotatingLogWriter { // InitLogRotator initializes the log file rotator to write logs to logFile and // create roll files in the same directory. It should be called as early on // startup and possible and must be closed on shutdown by calling `Close`. -func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string, - maxLogFileSize int, maxLogFiles int) error { +func (r *RotatingLogWriter) InitLogRotator(cfg *FileLoggerConfig, + logFile string) error { logDir, _ := filepath.Split(logFile) err := os.MkdirAll(logDir, 0700) @@ -41,19 +41,19 @@ func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string, } r.rotator, err = rotator.New( - logFile, int64(maxLogFileSize*1024), false, maxLogFiles, + logFile, int64(cfg.MaxLogFileSize*1024), false, cfg.MaxLogFiles, ) if err != nil { return fmt.Errorf("failed to create file rotator: %w", err) } // Reject unknown compressors. - if !SupportedLogCompressor(logCompressor) { - return fmt.Errorf("unknown log compressor: %v", logCompressor) + if !SupportedLogCompressor(cfg.Compressor) { + return fmt.Errorf("unknown log compressor: %v", cfg.Compressor) } var c rotator.Compressor - switch logCompressor { + switch cfg.Compressor { case Gzip: c = gzip.NewWriter(nil) @@ -66,7 +66,7 @@ func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string, } // Apply the compressor and its file suffix to the log rotator. - r.rotator.SetCompressor(c, logCompressors[logCompressor]) + r.rotator.SetCompressor(c, logCompressors[cfg.Compressor]) // Run rotator as a goroutine now but make sure we catch any errors // that happen in case something with the rotation goes wrong during diff --git a/config.go b/config.go index f9192aadc..5ac4dc307 100644 --- a/config.go +++ b/config.go @@ -71,8 +71,6 @@ const ( defaultChanEnableTimeout = 19 * time.Minute defaultChanDisableTimeout = 20 * time.Minute defaultHeightHintCacheQueryDisable = false - defaultMaxLogFiles = 3 - defaultMaxLogFileSize = 10 defaultMinBackoff = time.Second defaultMaxBackoff = time.Hour defaultLetsEncryptDirname = "letsencrypt" @@ -315,8 +313,8 @@ type Config struct { ReadMacPath string `long:"readonlymacaroonpath" description:"Path to write the read-only macaroon for lnd's RPC and REST services if it doesn't exist"` InvoiceMacPath string `long:"invoicemacaroonpath" description:"Path to the invoice-only macaroon for lnd's RPC and REST services if it doesn't exist"` LogDir string `long:"logdir" description:"Directory to log output."` - MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)"` - MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"` + MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation). DEPRECATED: use --logging.file.max-files instead" hidden:"true"` + MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB. DEPRECATED: use --logging.file.max-file-size instead" hidden:"true"` AcceptorTimeout time.Duration `long:"acceptortimeout" description:"Time after which an RPCAcceptor will time out and return false if it hasn't yet received a response"` LetsEncryptDir string `long:"letsencryptdir" description:"The directory to store Let's Encrypt certificates within"` @@ -562,8 +560,8 @@ func DefaultConfig() Config { LetsEncryptDir: defaultLetsEncryptDir, LetsEncryptListen: defaultLetsEncryptListen, LogDir: defaultLogDir, - MaxLogFiles: defaultMaxLogFiles, - MaxLogFileSize: defaultMaxLogFileSize, + MaxLogFiles: build.DefaultMaxLogFiles, + MaxLogFileSize: build.DefaultMaxLogFileSize, AcceptorTimeout: defaultAcceptorTimeout, WSPingInterval: lnrpc.DefaultPingInterval, WSPongWait: lnrpc.DefaultPongWait, @@ -1417,10 +1415,31 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, cfg.SubLogMgr.SupportedSubsystems()) os.Exit(0) } + + if cfg.MaxLogFiles != build.DefaultMaxLogFiles { + if cfg.LogConfig.File.MaxLogFiles != + build.DefaultMaxLogFiles { + + return nil, mkErr("cannot set both maxlogfiles and "+ + "logging.file.max-files", err) + } + + cfg.LogConfig.File.MaxLogFiles = cfg.MaxLogFiles + } + if cfg.MaxLogFileSize != build.DefaultMaxLogFileSize { + if cfg.LogConfig.File.MaxLogFileSize != + build.DefaultMaxLogFileSize { + + return nil, mkErr("cannot set both maxlogfilesize and "+ + "logging.file.max-file-size", err) + } + + cfg.LogConfig.File.MaxLogFileSize = cfg.MaxLogFileSize + } + err = cfg.LogRotator.InitLogRotator( + cfg.LogConfig.File, filepath.Join(cfg.LogDir, defaultLogFilename), - cfg.LogConfig.File.Compressor, cfg.MaxLogFileSize, - cfg.MaxLogFiles, ) if err != nil { str := "log rotation setup failed: %v" diff --git a/sample-lnd.conf b/sample-lnd.conf index b9aee40e5..66a97b70f 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -30,9 +30,12 @@ ; Rotated logs are compressed in place. ; logdir=~/.lnd/logs -; Number of logfiles that the log rotation should keep. Setting it to 0 disables deletion of old log files. +; DEPRECATED: Use logging.file.max-files instead. +; Number of logfiles that the log rotation should keep. Setting it to 0 disables +; deletion of old log files. ; maxlogfiles=3 ; +; DEPRECATED: Use logging.file.max-file-size instead. ; Max log file size in MB before it is rotated. ; maxlogfilesize=10 @@ -985,6 +988,13 @@ ; Disable logging to the standard LND log file. ; logging.file.disable=false +; Number of log files that the log rotation should keep. Setting +; it to 0 disables deletion of old log files. +; logging.file.max-files=3 + +; Max log file size in MB before it is rotated. +; logging.file.max-file-size=10 + ; Compression algorithm to use when rotating logs. ; Default: ; logging.file.compressor=gzip From 8106810d9eb42aca310ddb3fd499e6293ee0591d Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Oct 2024 18:12:18 +0200 Subject: [PATCH 6/7] docs: add release notes --- docs/release-notes/release-notes-0.19.0.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index 5116b4ba8..afba099e8 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -90,6 +90,12 @@ Finally, the new `--logging.console.style` option can be used under the `dev` build tag to add styling to console logging. +* [Add max files and max file size](https://github.com/lightningnetwork/lnd/pull/9233) + options to the `logging` config namespace under new `--logging.file.max-files` + and `--logging.files.max-file-size` options. The old options (`--maxlogfiles` + and `--maxlogfilesize`) will still work but deprecation notices have been + added and they will be removed in a future release. + ## Breaking Changes ## Performance Improvements From e547d2192069c6ebc07cd12e37deae1232ae6392 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 30 Oct 2024 13:23:18 +0200 Subject: [PATCH 7/7] multi: update log file max num and size defaults --- build/config.go | 4 ++-- docs/release-notes/release-notes-0.19.0.md | 4 +++- sample-lnd.conf | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build/config.go b/build/config.go index e26168f80..fd3b01a94 100644 --- a/build/config.go +++ b/build/config.go @@ -15,10 +15,10 @@ const ( // DefaultMaxLogFiles is the default maximum number of log files to // keep. - DefaultMaxLogFiles = 3 + DefaultMaxLogFiles = 10 // DefaultMaxLogFileSize is the default maximum log file size in MB. - DefaultMaxLogFileSize = 10 + DefaultMaxLogFileSize = 20 ) // LogConfig holds logging configuration options. diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index afba099e8..0e960bec8 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -94,7 +94,9 @@ options to the `logging` config namespace under new `--logging.file.max-files` and `--logging.files.max-file-size` options. The old options (`--maxlogfiles` and `--maxlogfilesize`) will still work but deprecation notices have been - added and they will be removed in a future release. + added and they will be removed in a future release. The defaults values for + these options have also been increased from max 3 log files to 10 and from + max 10 MB to 20 MB. ## Breaking Changes ## Performance Improvements diff --git a/sample-lnd.conf b/sample-lnd.conf index 66a97b70f..6d64603e8 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -33,11 +33,11 @@ ; DEPRECATED: Use logging.file.max-files instead. ; Number of logfiles that the log rotation should keep. Setting it to 0 disables ; deletion of old log files. -; maxlogfiles=3 +; maxlogfiles=10 ; ; DEPRECATED: Use logging.file.max-file-size instead. ; Max log file size in MB before it is rotated. -; maxlogfilesize=10 +; maxlogfilesize=20 ; Time after which an RPCAcceptor will time out and return false if ; it hasn't yet received a response. @@ -990,10 +990,10 @@ ; Number of log files that the log rotation should keep. Setting ; it to 0 disables deletion of old log files. -; logging.file.max-files=3 +; logging.file.max-files=10 ; Max log file size in MB before it is rotated. -; logging.file.max-file-size=10 +; logging.file.max-file-size=20 ; Compression algorithm to use when rotating logs. ; Default: