mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +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
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user