mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
lnd+build: add logcompressor flag
This commit is contained in:
parent
750770e190
commit
f360532eb1
26
build/log.go
26
build/log.go
@ -36,6 +36,32 @@ func (t LogType) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
// Declare the supported log file compressors as exported consts for easier use
|
||||
// from other projects.
|
||||
const (
|
||||
// Gzip is the default compressor.
|
||||
Gzip = "gzip"
|
||||
|
||||
// Zstd is a modern compressor that compresses better than Gzip, in less
|
||||
// time.
|
||||
Zstd = "zstd"
|
||||
)
|
||||
|
||||
// logCompressors maps the identifier for each supported compression algorithm
|
||||
// to the extension used for the compressed log files.
|
||||
var logCompressors = map[string]string{
|
||||
Gzip: "gz",
|
||||
Zstd: "zst",
|
||||
}
|
||||
|
||||
// SuportedLogCompressor returns whether or not logCompressor is a supported
|
||||
// compression algorithm for log files.
|
||||
func SuportedLogCompressor(logCompressor string) bool {
|
||||
_, ok := logCompressors[logCompressor]
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
// LogWriter is a stub type whose behavior can be changed using the build flags
|
||||
// "stdlog" and "nolog". The default behavior is to write to both stdout and the
|
||||
// RotatorPipe. Passing "stdlog" will cause it only to write to stdout, and
|
||||
|
@ -59,6 +59,7 @@ const (
|
||||
defaultLogLevel = "info"
|
||||
defaultLogDirname = "logs"
|
||||
defaultLogFilename = "lnd.log"
|
||||
defaultLogCompressor = build.Gzip
|
||||
defaultRPCPort = 10009
|
||||
defaultRESTPort = 8080
|
||||
defaultPeerPort = 9735
|
||||
@ -315,6 +316,7 @@ 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"`
|
||||
@ -560,6 +562,7 @@ func DefaultConfig() Config {
|
||||
LetsEncryptDir: defaultLetsEncryptDir,
|
||||
LetsEncryptListen: defaultLetsEncryptListen,
|
||||
LogDir: defaultLogDir,
|
||||
LogCompressor: defaultLogCompressor,
|
||||
MaxLogFiles: defaultMaxLogFiles,
|
||||
MaxLogFileSize: defaultMaxLogFileSize,
|
||||
AcceptorTimeout: defaultAcceptorTimeout,
|
||||
@ -1446,6 +1449,11 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if !build.SuportedLogCompressor(cfg.LogCompressor) {
|
||||
return nil, mkErr("invalid log compressor: %v",
|
||||
cfg.LogCompressor)
|
||||
}
|
||||
|
||||
// Initialize logging at the default logging level.
|
||||
SetupLoggers(cfg.LogWriter, interceptor)
|
||||
err = cfg.LogWriter.InitLogRotator(
|
||||
|
@ -36,6 +36,9 @@
|
||||
; 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
|
||||
|
Loading…
Reference in New Issue
Block a user