multi: move logcompressor to logging.file.compressor

This is not a breaking change since the logcompressor config option has
not been released yet.
This commit is contained in:
Elle Mouton 2024-10-29 17:58:23 +02:00
parent 1886d3865b
commit 3adbdbb39a
No known key found for this signature in database
GPG Key ID: D7D916376026F177
6 changed files with 37 additions and 15 deletions

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

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

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

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

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

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