@@ -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
@@ -75,6 +77,9 @@ func (p *PeerSwapConfig) String() string {
7577}
7678
7779func (p * PeerSwapConfig ) Validate () error {
80+ if err := p .LogRotation .Validate (); err != nil {
81+ return err
82+ }
7883 if p .ElementsConfig .RpcHost != "" && p .ElementsConfig .LiquidSwaps != false {
7984 err := p .ElementsConfig .Validate ()
8085 if err != nil {
@@ -139,6 +144,28 @@ type LndConfig struct {
139144 MacaroonPath string `long:"macaroonpath" description:"path to the macaroon (admin.macaroon or custom baked one)"`
140145}
141146
147+ type LogRotationConfig struct {
148+ // In megabytes
149+ MaxSize int `long:"maxsize" description:"maximum size in megabytes of the log file before rotation."`
150+ MaxBackups int `long:"maxbackups" description:"maximum number of old log files to retain."`
151+ // In days
152+ MaxAge int `long:"maxage" description:"maximum number of days to retain old log files."`
153+ Compress bool `long:"compress" description:"whether to compress log files using gzip"`
154+ }
155+
156+ func (l LogRotationConfig ) Validate () error {
157+ if l .MaxSize <= 0 {
158+ return fmt .Errorf ("logrotation.maxsize must be > 0, got %d" , l .MaxSize )
159+ }
160+ if l .MaxBackups < 0 {
161+ return fmt .Errorf ("logrotation.maxbackups must be >= 0, got %d" , l .MaxBackups )
162+ }
163+ if l .MaxAge < 0 {
164+ return fmt .Errorf ("logrotation.maxage must be >= 0, got %d" , l .MaxAge )
165+ }
166+ return nil
167+ }
168+
142169func DefaultConfig () * PeerSwapConfig {
143170 return & PeerSwapConfig {
144171 Host : DefaultPeerswapHost ,
@@ -154,6 +181,7 @@ func DefaultConfig() *PeerSwapConfig {
154181 BitcoinEnabled : DefaultBitcoinEnabled ,
155182 ElementsConfig : defaultLiquidConfig (),
156183 LogLevel : DefaultLogLevel ,
184+ LogRotation : defaultLogRotationConfig (),
157185 }
158186}
159187
@@ -170,6 +198,15 @@ func defaultLiquidConfig() *OnchainConfig {
170198 }
171199}
172200
201+ func defaultLogRotationConfig () LogRotationConfig {
202+ return LogRotationConfig {
203+ MaxSize : 10 ,
204+ MaxBackups : 5 ,
205+ MaxAge : 28 ,
206+ Compress : true ,
207+ }
208+ }
209+
173210func LWKFromIniFileConfig (filePath string ) (* lwk.Conf , error ) {
174211 type LWK struct {
175212 SignerName string `long:"signername" description:"name of the signer"`
0 commit comments