Skip to content

Commit f360532

Browse files
committed
lnd+build: add logcompressor flag
1 parent 750770e commit f360532

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

build/log.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,32 @@ func (t LogType) String() string {
3636
}
3737
}
3838

39+
// Declare the supported log file compressors as exported consts for easier use
40+
// from other projects.
41+
const (
42+
// Gzip is the default compressor.
43+
Gzip = "gzip"
44+
45+
// Zstd is a modern compressor that compresses better than Gzip, in less
46+
// time.
47+
Zstd = "zstd"
48+
)
49+
50+
// logCompressors maps the identifier for each supported compression algorithm
51+
// to the extension used for the compressed log files.
52+
var logCompressors = map[string]string{
53+
Gzip: "gz",
54+
Zstd: "zst",
55+
}
56+
57+
// SuportedLogCompressor returns whether or not logCompressor is a supported
58+
// compression algorithm for log files.
59+
func SuportedLogCompressor(logCompressor string) bool {
60+
_, ok := logCompressors[logCompressor]
61+
62+
return ok
63+
}
64+
3965
// LogWriter is a stub type whose behavior can be changed using the build flags
4066
// "stdlog" and "nolog". The default behavior is to write to both stdout and the
4167
// RotatorPipe. Passing "stdlog" will cause it only to write to stdout, and

config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const (
5959
defaultLogLevel = "info"
6060
defaultLogDirname = "logs"
6161
defaultLogFilename = "lnd.log"
62+
defaultLogCompressor = build.Gzip
6263
defaultRPCPort = 10009
6364
defaultRESTPort = 8080
6465
defaultPeerPort = 9735
@@ -315,6 +316,7 @@ type Config struct {
315316
ReadMacPath string `long:"readonlymacaroonpath" description:"Path to write the read-only macaroon for lnd's RPC and REST services if it doesn't exist"`
316317
InvoiceMacPath string `long:"invoicemacaroonpath" description:"Path to the invoice-only macaroon for lnd's RPC and REST services if it doesn't exist"`
317318
LogDir string `long:"logdir" description:"Directory to log output."`
319+
LogCompressor string `long:"logcompressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"`
318320
MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)"`
319321
MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"`
320322
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 {
560562
LetsEncryptDir: defaultLetsEncryptDir,
561563
LetsEncryptListen: defaultLetsEncryptListen,
562564
LogDir: defaultLogDir,
565+
LogCompressor: defaultLogCompressor,
563566
MaxLogFiles: defaultMaxLogFiles,
564567
MaxLogFileSize: defaultMaxLogFileSize,
565568
AcceptorTimeout: defaultAcceptorTimeout,
@@ -1446,6 +1449,11 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
14461449
os.Exit(0)
14471450
}
14481451

1452+
if !build.SuportedLogCompressor(cfg.LogCompressor) {
1453+
return nil, mkErr("invalid log compressor: %v",
1454+
cfg.LogCompressor)
1455+
}
1456+
14491457
// Initialize logging at the default logging level.
14501458
SetupLoggers(cfg.LogWriter, interceptor)
14511459
err = cfg.LogWriter.InitLogRotator(

sample-lnd.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
; Max log file size in MB before it is rotated.
3737
; maxlogfilesize=10
3838

39+
; Compression algorithm to use when rotating logs.
40+
; logcompressor=gzip
41+
3942
; Time after which an RPCAcceptor will time out and return false if
4043
; it hasn't yet received a response.
4144
; acceptortimeout=15s

0 commit comments

Comments
 (0)