Skip to content

Commit 9c3993a

Browse files
committed
feat: configuration for log rotation
1 parent c56fbd7 commit 9c3993a

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

cmd/peerswaplnd/config.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type PeerSwapConfig struct {
4444
DataDir string `long:"datadir" description:"peerswap datadir"`
4545
LogLevel LogLevel `long:"loglevel" description:"loglevel (1=Info, 2=Debug)"`
4646

47+
LogRotation LogRotationConfig `group:"Log rotation" namespace:"logrotation"`
48+
4749
LndConfig *LndConfig `group:"Lnd Grpc config" namespace:"lnd"`
4850
ElementsConfig *OnchainConfig `group:"Elements Rpc Config" namespace:"elementsd"`
4951
LWKConfig *lwk.Conf
@@ -139,6 +141,15 @@ type LndConfig struct {
139141
MacaroonPath string `long:"macaroonpath" description:"path to the macaroon (admin.macaroon or custom baked one)"`
140142
}
141143

144+
type LogRotationConfig struct {
145+
// In megabytes
146+
MaxSize int `long:"maxsize" description:"maximum size in megabytes of the log file before rotation."`
147+
MaxBackups int `long:"maxbackups" description:"maximum number of old log files to retain."`
148+
// In days
149+
MaxAge int `long:"maxage" description:"maximum number of days to retain old log files."`
150+
Compress bool `long:"compress" description:"whether to compress log files using gzip"`
151+
}
152+
142153
func DefaultConfig() *PeerSwapConfig {
143154
return &PeerSwapConfig{
144155
Host: DefaultPeerswapHost,
@@ -154,6 +165,7 @@ func DefaultConfig() *PeerSwapConfig {
154165
BitcoinEnabled: DefaultBitcoinEnabled,
155166
ElementsConfig: defaultLiquidConfig(),
156167
LogLevel: DefaultLogLevel,
168+
LogRotation: defaultLogRotationConfig(),
157169
}
158170
}
159171

@@ -170,6 +182,15 @@ func defaultLiquidConfig() *OnchainConfig {
170182
}
171183
}
172184

185+
func defaultLogRotationConfig() LogRotationConfig {
186+
return LogRotationConfig{
187+
MaxSize: 10,
188+
MaxBackups: 5,
189+
MaxAge: 28,
190+
Compress: true,
191+
}
192+
}
193+
173194
func LWKFromIniFileConfig(filePath string) (*lwk.Conf, error) {
174195
type LWK struct {
175196
SignerName string `long:"signername" description:"name of the signer"`

cmd/peerswaplnd/peerswapd/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,10 @@ func NewLndLogger(cfg *peerswaplnd.PeerSwapConfig) (*LndLogger, error) {
602602
core_log.SetFlags(core_log.LstdFlags | core_log.LUTC)
603603
core_log.SetOutput(&lumberjack.Logger{
604604
Filename: logFile,
605-
MaxSize: 10, // megabytes
606-
MaxBackups: 5,
607-
MaxAge: 28, // days
608-
Compress: true,
605+
MaxSize: cfg.LogRotation.MaxSize,
606+
MaxBackups: cfg.LogRotation.MaxBackups,
607+
MaxAge: cfg.LogRotation.MaxAge,
608+
Compress: cfg.LogRotation.Compress,
609609
})
610610

611611
return &LndLogger{loglevel: cfg.LogLevel}, nil

0 commit comments

Comments
 (0)