build+config: move maxlogfiles and maxfilesize to logger config
Add deprecation notices but continue to read both.
This commit is contained in:
4 files changed
+58
-18
No files matched your search
+13
-2
@@ -12,6 +12,13 @@ const (
|
|||||||
callSiteLong = "long"
|
callSiteLong = "long"
|
||||||
|
|
||||||
defaultLogCompressor = Gzip
|
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.
|
// LogConfig holds logging configuration options.
|
||||||
@@ -46,7 +53,9 @@ func DefaultLogConfig() *LogConfig {
|
|||||||
return &LogConfig{
|
return &LogConfig{
|
||||||
Console: defaultConsoleLoggerCfg(),
|
Console: defaultConsoleLoggerCfg(),
|
||||||
File: &FileLoggerConfig{
|
File: &FileLoggerConfig{
|
||||||
Compressor: defaultLogCompressor,
|
Compressor: defaultLogCompressor,
|
||||||
|
MaxLogFiles: DefaultMaxLogFiles,
|
||||||
|
MaxLogFileSize: DefaultMaxLogFileSize,
|
||||||
LoggerConfig: LoggerConfig{
|
LoggerConfig: LoggerConfig{
|
||||||
CallSite: callSiteOff,
|
CallSite: callSiteOff,
|
||||||
},
|
},
|
||||||
@@ -84,5 +93,7 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption {
|
|||||||
//nolint:lll
|
//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"`
|
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"`
|
||||||
}
|
}
|
||||||
+7
-7
@@ -31,8 +31,8 @@ func NewRotatingLogWriter() *RotatingLogWriter {
|
|||||||
// InitLogRotator initializes the log file rotator to write logs to logFile and
|
// 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
|
// 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`.
|
// startup and possible and must be closed on shutdown by calling `Close`.
|
||||||
func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string,
|
func (r *RotatingLogWriter) InitLogRotator(cfg *FileLoggerConfig,
|
||||||
maxLogFileSize int, maxLogFiles int) error {
|
logFile string) error {
|
||||||
|
|
||||||
logDir, _ := filepath.Split(logFile)
|
logDir, _ := filepath.Split(logFile)
|
||||||
err := os.MkdirAll(logDir, 0700)
|
err := os.MkdirAll(logDir, 0700)
|
||||||
@@ -41,19 +41,19 @@ func (r *RotatingLogWriter) InitLogRotator(logFile, logCompressor string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.rotator, err = rotator.New(
|
r.rotator, err = rotator.New(
|
||||||
logFile, int64(maxLogFileSize*1024), false, maxLogFiles,
|
logFile, int64(cfg.MaxLogFileSize*1024), false, cfg.MaxLogFiles,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create file rotator: %w", err)
|
return fmt.Errorf("failed to create file rotator: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject unknown compressors.
|
// Reject unknown compressors.
|
||||||
if !SupportedLogCompressor(logCompressor) {
|
if !SupportedLogCompressor(cfg.Compressor) {
|
||||||
return fmt.Errorf("unknown log compressor: %v", logCompressor)
|
return fmt.Errorf("unknown log compressor: %v", cfg.Compressor)
|
||||||
}
|
}
|
||||||
|
|
||||||
var c rotator.Compressor
|
var c rotator.Compressor
|
||||||
switch logCompressor {
|
switch cfg.Compressor {
|
||||||
case Gzip:
|
case Gzip:
|
||||||
c = gzip.NewWriter(nil)
|
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.
|
// 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
|
// Run rotator as a goroutine now but make sure we catch any errors
|
||||||
// that happen in case something with the rotation goes wrong during
|
// that happen in case something with the rotation goes wrong during
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ const (
|
|||||||
defaultChanEnableTimeout = 19 * time.Minute
|
defaultChanEnableTimeout = 19 * time.Minute
|
||||||
defaultChanDisableTimeout = 20 * time.Minute
|
defaultChanDisableTimeout = 20 * time.Minute
|
||||||
defaultHeightHintCacheQueryDisable = false
|
defaultHeightHintCacheQueryDisable = false
|
||||||
defaultMaxLogFiles = 3
|
|
||||||
defaultMaxLogFileSize = 10
|
|
||||||
defaultMinBackoff = time.Second
|
defaultMinBackoff = time.Second
|
||||||
defaultMaxBackoff = time.Hour
|
defaultMaxBackoff = time.Hour
|
||||||
defaultLetsEncryptDirname = "letsencrypt"
|
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"`
|
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."`
|
||||||
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). DEPRECATED: use --logging.file.max-files instead" hidden:"true"`
|
||||||
MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"`
|
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"`
|
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"`
|
LetsEncryptDir string `long:"letsencryptdir" description:"The directory to store Let's Encrypt certificates within"`
|
||||||
@@ -562,8 +560,8 @@ func DefaultConfig() Config {
|
|||||||
LetsEncryptDir: defaultLetsEncryptDir,
|
LetsEncryptDir: defaultLetsEncryptDir,
|
||||||
LetsEncryptListen: defaultLetsEncryptListen,
|
LetsEncryptListen: defaultLetsEncryptListen,
|
||||||
LogDir: defaultLogDir,
|
LogDir: defaultLogDir,
|
||||||
MaxLogFiles: defaultMaxLogFiles,
|
MaxLogFiles: build.DefaultMaxLogFiles,
|
||||||
MaxLogFileSize: defaultMaxLogFileSize,
|
MaxLogFileSize: build.DefaultMaxLogFileSize,
|
||||||
AcceptorTimeout: defaultAcceptorTimeout,
|
AcceptorTimeout: defaultAcceptorTimeout,
|
||||||
WSPingInterval: lnrpc.DefaultPingInterval,
|
WSPingInterval: lnrpc.DefaultPingInterval,
|
||||||
WSPongWait: lnrpc.DefaultPongWait,
|
WSPongWait: lnrpc.DefaultPongWait,
|
||||||
@@ -1417,10 +1415,31 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
|
|||||||
cfg.SubLogMgr.SupportedSubsystems())
|
cfg.SubLogMgr.SupportedSubsystems())
|
||||||
os.Exit(0)
|
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(
|
err = cfg.LogRotator.InitLogRotator(
|
||||||
|
cfg.LogConfig.File,
|
||||||
filepath.Join(cfg.LogDir, defaultLogFilename),
|
filepath.Join(cfg.LogDir, defaultLogFilename),
|
||||||
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"
|
||||||
|
|||||||
+11
-1
@@ -30,9 +30,12 @@
|
|||||||
; Rotated logs are compressed in place.
|
; Rotated logs are compressed in place.
|
||||||
; logdir=~/.lnd/logs
|
; 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
|
; maxlogfiles=3
|
||||||
;
|
;
|
||||||
|
; DEPRECATED: Use logging.file.max-file-size instead.
|
||||||
; Max log file size in MB before it is rotated.
|
; Max log file size in MB before it is rotated.
|
||||||
; maxlogfilesize=10
|
; maxlogfilesize=10
|
||||||
|
|
||||||
@@ -985,6 +988,13 @@
|
|||||||
; Disable logging to the standard LND log file.
|
; Disable logging to the standard LND log file.
|
||||||
; logging.file.disable=false
|
; 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.
|
; Compression algorithm to use when rotating logs.
|
||||||
; Default:
|
; Default:
|
||||||
; logging.file.compressor=gzip
|
; logging.file.compressor=gzip
|
||||||
|
|||||||
Reference in new issue
Block a user