config: make log rotation configurable
This commit is contained in:
parent
80d57f3ddf
commit
5eed171187
@ -46,6 +46,8 @@ const (
|
|||||||
defaultMaxPendingChannels = 1
|
defaultMaxPendingChannels = 1
|
||||||
defaultNoEncryptWallet = false
|
defaultNoEncryptWallet = false
|
||||||
defaultTrickleDelay = 30 * 1000
|
defaultTrickleDelay = 30 * 1000
|
||||||
|
defaultMaxLogFiles = 3
|
||||||
|
defaultMaxLogFileSize = 10
|
||||||
|
|
||||||
defaultBroadcastDelta = 10
|
defaultBroadcastDelta = 10
|
||||||
|
|
||||||
@ -157,7 +159,8 @@ 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"`
|
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"`
|
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."`
|
LogDir string `long:"logdir" description:"Directory to log output."`
|
||||||
|
MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)"`
|
||||||
|
MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"`
|
||||||
RPCListeners []string `long:"rpclisten" description:"Add an interface/port to listen for RPC connections"`
|
RPCListeners []string `long:"rpclisten" description:"Add an interface/port to listen for RPC connections"`
|
||||||
RESTListeners []string `long:"restlisten" description:"Add an interface/port to listen for REST connections"`
|
RESTListeners []string `long:"restlisten" description:"Add an interface/port to listen for REST connections"`
|
||||||
Listeners []string `long:"listen" description:"Add an interface/port to listen for peer connections"`
|
Listeners []string `long:"listen" description:"Add an interface/port to listen for peer connections"`
|
||||||
@ -222,6 +225,8 @@ func loadConfig() (*config, error) {
|
|||||||
InvoiceMacPath: defaultInvoiceMacPath,
|
InvoiceMacPath: defaultInvoiceMacPath,
|
||||||
ReadMacPath: defaultReadMacPath,
|
ReadMacPath: defaultReadMacPath,
|
||||||
LogDir: defaultLogDir,
|
LogDir: defaultLogDir,
|
||||||
|
MaxLogFiles: defaultMaxLogFiles,
|
||||||
|
MaxLogFileSize: defaultMaxLogFileSize,
|
||||||
Bitcoin: &chainConfig{
|
Bitcoin: &chainConfig{
|
||||||
MinHTLC: defaultBitcoinMinHTLCMSat,
|
MinHTLC: defaultBitcoinMinHTLCMSat,
|
||||||
BaseFee: defaultBitcoinBaseFeeMSat,
|
BaseFee: defaultBitcoinBaseFeeMSat,
|
||||||
@ -662,7 +667,7 @@ func loadConfig() (*config, error) {
|
|||||||
normalizeNetwork(activeNetParams.Name))
|
normalizeNetwork(activeNetParams.Name))
|
||||||
|
|
||||||
// Initialize logging at the default logging level.
|
// Initialize logging at the default logging level.
|
||||||
initLogRotator(filepath.Join(cfg.LogDir, defaultLogFilename))
|
initLogRotator(filepath.Join(cfg.LogDir, defaultLogFilename), cfg.MaxLogFileSize, cfg.MaxLogFiles)
|
||||||
|
|
||||||
// Parse, validate, and set debug log level(s).
|
// Parse, validate, and set debug log level(s).
|
||||||
if err := parseAndSetDebugLevels(cfg.DebugLevel); err != nil {
|
if err := parseAndSetDebugLevels(cfg.DebugLevel); err != nil {
|
||||||
|
4
log.go
4
log.go
@ -116,14 +116,14 @@ var subsystemLoggers = map[string]btclog.Logger{
|
|||||||
// initLogRotator initializes the logging rotator to write logs to logFile and
|
// initLogRotator initializes the logging rotator to write logs to logFile and
|
||||||
// create roll files in the same directory. It must be called before the
|
// create roll files in the same directory. It must be called before the
|
||||||
// package-global log rotator variables are used.
|
// package-global log rotator variables are used.
|
||||||
func initLogRotator(logFile string) {
|
func initLogRotator(logFile string, MaxLogFileSize int, MaxLogFiles int) {
|
||||||
logDir, _ := filepath.Split(logFile)
|
logDir, _ := filepath.Split(logFile)
|
||||||
err := os.MkdirAll(logDir, 0700)
|
err := os.MkdirAll(logDir, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
|
fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
r, err := rotator.New(logFile, 10*1024, false, 3)
|
r, err := rotator.New(logFile, int64(MaxLogFileSize*1024), false, MaxLogFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
|
fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -12,6 +12,12 @@
|
|||||||
; Rotated logs are compressed in place.
|
; Rotated logs are compressed in place.
|
||||||
; logdir=~/.lnd/logs
|
; logdir=~/.lnd/logs
|
||||||
|
|
||||||
|
; Number of logfiles that the log rotation should keep. Setting it to 0 disables deletion of old log files.
|
||||||
|
; maxlogfiles=3
|
||||||
|
;
|
||||||
|
; Max log file size in MB before it is rotated.
|
||||||
|
; maxlogfilesize=10
|
||||||
|
|
||||||
; Path to TLS certificate for lnd's RPC and REST services.
|
; Path to TLS certificate for lnd's RPC and REST services.
|
||||||
; tlscertpath=~/.lnd/tls.cert
|
; tlscertpath=~/.lnd/tls.cert
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user