mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-07 22:10:27 +02:00
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:
@ -1,11 +1,17 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import "github.com/btcsuite/btclog/v2"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btclog/v2"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
callSiteOff = "off"
|
callSiteOff = "off"
|
||||||
callSiteShort = "short"
|
callSiteShort = "short"
|
||||||
callSiteLong = "long"
|
callSiteLong = "long"
|
||||||
|
|
||||||
|
defaultLogCompressor = Gzip
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogConfig holds logging configuration options.
|
// 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."`
|
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.
|
// LoggerConfig holds options for a particular logger.
|
||||||
//
|
//
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
@ -30,6 +46,7 @@ func DefaultLogConfig() *LogConfig {
|
|||||||
return &LogConfig{
|
return &LogConfig{
|
||||||
Console: defaultConsoleLoggerCfg(),
|
Console: defaultConsoleLoggerCfg(),
|
||||||
File: &FileLoggerConfig{
|
File: &FileLoggerConfig{
|
||||||
|
Compressor: defaultLogCompressor,
|
||||||
LoggerConfig: LoggerConfig{
|
LoggerConfig: LoggerConfig{
|
||||||
CallSite: callSiteOff,
|
CallSite: callSiteOff,
|
||||||
},
|
},
|
||||||
@ -63,6 +80,9 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FileLoggerConfig extends LoggerConfig with specific log file options.
|
// FileLoggerConfig extends LoggerConfig with specific log file options.
|
||||||
|
//
|
||||||
|
//nolint:lll
|
||||||
type FileLoggerConfig struct {
|
type FileLoggerConfig struct {
|
||||||
LoggerConfig
|
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",
|
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.
|
// compression algorithm for log files.
|
||||||
func SuportedLogCompressor(logCompressor string) bool {
|
func SupportedLogCompressor(logCompressor string) bool {
|
||||||
_, ok := logCompressors[logCompressor]
|
_, ok := logCompressors[logCompressor]
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
|
@ -48,7 +48,7 @@ func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reject unknown compressors.
|
// Reject unknown compressors.
|
||||||
if !SuportedLogCompressor(logCompressor) {
|
if !SupportedLogCompressor(logCompressor) {
|
||||||
return fmt.Errorf("unknown log compressor: %v", logCompressor)
|
return fmt.Errorf("unknown log compressor: %v", logCompressor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
config.go
11
config.go
@ -59,7 +59,6 @@ const (
|
|||||||
defaultLogLevel = "info"
|
defaultLogLevel = "info"
|
||||||
defaultLogDirname = "logs"
|
defaultLogDirname = "logs"
|
||||||
defaultLogFilename = "lnd.log"
|
defaultLogFilename = "lnd.log"
|
||||||
defaultLogCompressor = build.Gzip
|
|
||||||
defaultRPCPort = 10009
|
defaultRPCPort = 10009
|
||||||
defaultRESTPort = 8080
|
defaultRESTPort = 8080
|
||||||
defaultPeerPort = 9735
|
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"`
|
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"`
|
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."`
|
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)"`
|
MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)"`
|
||||||
MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"`
|
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"`
|
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,
|
LetsEncryptDir: defaultLetsEncryptDir,
|
||||||
LetsEncryptListen: defaultLetsEncryptListen,
|
LetsEncryptListen: defaultLetsEncryptListen,
|
||||||
LogDir: defaultLogDir,
|
LogDir: defaultLogDir,
|
||||||
LogCompressor: defaultLogCompressor,
|
|
||||||
MaxLogFiles: defaultMaxLogFiles,
|
MaxLogFiles: defaultMaxLogFiles,
|
||||||
MaxLogFileSize: defaultMaxLogFileSize,
|
MaxLogFileSize: defaultMaxLogFileSize,
|
||||||
AcceptorTimeout: defaultAcceptorTimeout,
|
AcceptorTimeout: defaultAcceptorTimeout,
|
||||||
@ -1403,9 +1400,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
|
|||||||
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
if !build.SuportedLogCompressor(cfg.LogCompressor) {
|
if err := cfg.LogConfig.Validate(); err != nil {
|
||||||
return nil, mkErr("invalid log compressor: %v",
|
return nil, mkErr("error validating logging config: %w", err)
|
||||||
cfg.LogCompressor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.SubLogMgr = build.NewSubLoggerManager(build.NewDefaultLogHandlers(
|
cfg.SubLogMgr = build.NewSubLoggerManager(build.NewDefaultLogHandlers(
|
||||||
@ -1423,7 +1419,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
|
|||||||
}
|
}
|
||||||
err = cfg.LogRotator.InitLogRotator(
|
err = cfg.LogRotator.InitLogRotator(
|
||||||
filepath.Join(cfg.LogDir, defaultLogFilename),
|
filepath.Join(cfg.LogDir, defaultLogFilename),
|
||||||
cfg.LogCompressor, cfg.MaxLogFileSize, cfg.MaxLogFiles,
|
cfg.LogConfig.File.Compressor, cfg.MaxLogFileSize,
|
||||||
|
cfg.MaxLogFiles,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
str := "log rotation setup failed: %v"
|
str := "log rotation setup failed: %v"
|
||||||
|
@ -57,7 +57,9 @@
|
|||||||
# Improvements
|
# Improvements
|
||||||
## Functional Updates
|
## 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]
|
* 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
|
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.
|
; Max log file size in MB before it is rotated.
|
||||||
; maxlogfilesize=10
|
; maxlogfilesize=10
|
||||||
|
|
||||||
; Compression algorithm to use when rotating logs.
|
|
||||||
; logcompressor=gzip
|
|
||||||
|
|
||||||
; Time after which an RPCAcceptor will time out and return false if
|
; Time after which an RPCAcceptor will time out and return false if
|
||||||
; it hasn't yet received a response.
|
; it hasn't yet received a response.
|
||||||
; acceptortimeout=15s
|
; acceptortimeout=15s
|
||||||
@ -988,6 +985,12 @@
|
|||||||
; Disable logging to the standard LND log file.
|
; Disable logging to the standard LND log file.
|
||||||
; logging.file.disable=false
|
; 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.
|
; Don't add timestamps to logs written to the standard LND log file.
|
||||||
; logging.file.no-timestamps=false
|
; logging.file.no-timestamps=false
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user