-
Notifications
You must be signed in to change notification settings - Fork 2.3k
build+config: move file logger specific options to logging.file
#9233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4c5e565
0512357
1886d38
3adbdbb
22c1379
8106810
e547d21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,42 @@ | ||
| //go:build !dev | ||
| // +build !dev | ||
|
|
||
| package build | ||
|
|
||
| import "github.com/btcsuite/btclog/v2" | ||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/btcsuite/btclog/v2" | ||
| ) | ||
|
|
||
| const ( | ||
| callSiteOff = "off" | ||
| callSiteShort = "short" | ||
| callSiteLong = "long" | ||
|
|
||
| defaultLogCompressor = Gzip | ||
|
|
||
| // DefaultMaxLogFiles is the default maximum number of log files to | ||
| // keep. | ||
| DefaultMaxLogFiles = 10 | ||
|
|
||
| // DefaultMaxLogFileSize is the default maximum log file size in MB. | ||
| DefaultMaxLogFileSize = 20 | ||
| ) | ||
|
|
||
| // LogConfig holds logging configuration options. | ||
| // | ||
| //nolint:lll | ||
| type LogConfig struct { | ||
| Console *LoggerConfig `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."` | ||
| File *LoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` | ||
| Console *consoleLoggerCfg `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."` | ||
| File *FileLoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."` | ||
| } | ||
|
|
||
| // DefaultLogConfig returns the default logging config options. | ||
| func DefaultLogConfig() *LogConfig { | ||
| return &LogConfig{ | ||
| Console: &LoggerConfig{ | ||
| CallSite: callSiteOff, | ||
| }, | ||
| File: &LoggerConfig{ | ||
| CallSite: callSiteOff, | ||
| }, | ||
| // Validate validates the LogConfig struct values. | ||
| func (c *LogConfig) Validate() error { | ||
| if !SupportedLogCompressor(c.File.Compressor) { | ||
| return fmt.Errorf("invalid log compressor: %v", | ||
| c.File.Compressor) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // LoggerConfig holds options for a particular logger. | ||
|
|
@@ -40,6 +48,21 @@ type LoggerConfig struct { | |
| CallSite string `long:"call-site" description:"Include the call-site of each log line." choice:"off" choice:"short" choice:"long"` | ||
| } | ||
|
|
||
| // DefaultLogConfig returns the default logging config options. | ||
| func DefaultLogConfig() *LogConfig { | ||
| return &LogConfig{ | ||
| Console: defaultConsoleLoggerCfg(), | ||
| File: &FileLoggerConfig{ | ||
| Compressor: defaultLogCompressor, | ||
| MaxLogFiles: DefaultMaxLogFiles, | ||
| MaxLogFileSize: DefaultMaxLogFileSize, | ||
| LoggerConfig: LoggerConfig{ | ||
| CallSite: callSiteOff, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // HandlerOptions returns the set of btclog.HandlerOptions that the state of the | ||
| // config struct translates to. | ||
| func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { | ||
|
|
@@ -50,6 +73,7 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { | |
| // to 7 here. | ||
| btclog.WithCallSiteSkipDepth(7), | ||
| } | ||
|
|
||
| if cfg.NoTimestamps { | ||
| opts = append(opts, btclog.WithNoTimestamp()) | ||
| } | ||
|
|
@@ -63,3 +87,13 @@ func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption { | |
|
|
||
| return opts | ||
| } | ||
|
|
||
| // FileLoggerConfig extends LoggerConfig with specific log file options. | ||
| // | ||
| //nolint:lll | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed now?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wanted to comment the same when going through it commit by commit. But longer lines are added to it later, so I think it's still needed.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah lol 🙃 will re-add (in correct commit)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh ok didn't notice that😂 |
||
| type FileLoggerConfig struct { | ||
| LoggerConfig | ||
| Compressor string `long:"compressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"` | ||
| MaxLogFiles int `long:"max-files" description:"Maximum logfiles to keep (0 for no rotation)"` | ||
| MaxLogFileSize int `long:"max-file-size" description:"Maximum logfile size in MB"` | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //go:build !dev | ||
| // +build !dev | ||
|
|
||
| package build | ||
|
|
||
| // consoleLoggerCfg embeds the LoggerConfig struct along with any extensions | ||
| // specific to a production deployment. | ||
| // | ||
| //nolint:lll | ||
| type consoleLoggerCfg struct { | ||
| LoggerConfig | ||
| } | ||
|
|
||
| // defaultConsoleLoggerCfg returns the default consoleLoggerCfg for the prod | ||
| // console logger. | ||
| func defaultConsoleLoggerCfg() *consoleLoggerCfg { | ||
| return &consoleLoggerCfg{ | ||
| LoggerConfig: LoggerConfig{ | ||
| CallSite: callSiteOff, | ||
| }, | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,6 @@ const ( | |
| defaultLogLevel = "info" | ||
| defaultLogDirname = "logs" | ||
| defaultLogFilename = "lnd.log" | ||
| defaultLogCompressor = build.Gzip | ||
| defaultRPCPort = 10009 | ||
| defaultRESTPort = 8080 | ||
| defaultPeerPort = 9735 | ||
|
|
@@ -72,8 +71,6 @@ const ( | |
| defaultChanEnableTimeout = 19 * time.Minute | ||
| defaultChanDisableTimeout = 20 * time.Minute | ||
| defaultHeightHintCacheQueryDisable = false | ||
| defaultMaxLogFiles = 3 | ||
| defaultMaxLogFileSize = 10 | ||
| defaultMinBackoff = time.Second | ||
| defaultMaxBackoff = time.Hour | ||
| defaultLetsEncryptDirname = "letsencrypt" | ||
|
|
@@ -316,9 +313,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"` | ||
| 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"` | ||
| MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation). DEPRECATED: use --logging.file.max-files instead" hidden:"true"` | ||
| MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB. DEPRECATED: use --logging.file.max-file-size instead" hidden:"true"` | ||
| 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"` | ||
|
|
||
| LetsEncryptDir string `long:"letsencryptdir" description:"The directory to store Let's Encrypt certificates within"` | ||
|
|
@@ -564,9 +560,8 @@ func DefaultConfig() Config { | |
| LetsEncryptDir: defaultLetsEncryptDir, | ||
| LetsEncryptListen: defaultLetsEncryptListen, | ||
| LogDir: defaultLogDir, | ||
| LogCompressor: defaultLogCompressor, | ||
| MaxLogFiles: defaultMaxLogFiles, | ||
| MaxLogFileSize: defaultMaxLogFileSize, | ||
| MaxLogFiles: build.DefaultMaxLogFiles, | ||
| MaxLogFileSize: build.DefaultMaxLogFileSize, | ||
| AcceptorTimeout: defaultAcceptorTimeout, | ||
| WSPingInterval: lnrpc.DefaultPingInterval, | ||
| WSPongWait: lnrpc.DefaultPongWait, | ||
|
|
@@ -1403,9 +1398,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, | |
| lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name), | ||
| ) | ||
|
|
||
| if !build.SuportedLogCompressor(cfg.LogCompressor) { | ||
| return nil, mkErr("invalid log compressor: %v", | ||
| cfg.LogCompressor) | ||
| if err := cfg.LogConfig.Validate(); err != nil { | ||
| return nil, mkErr("error validating logging config: %w", err) | ||
| } | ||
|
|
||
| cfg.SubLogMgr = build.NewSubLoggerManager(build.NewDefaultLogHandlers( | ||
|
|
@@ -1421,9 +1415,31 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, | |
| cfg.SubLogMgr.SupportedSubsystems()) | ||
| os.Exit(0) | ||
| } | ||
|
|
||
| if cfg.MaxLogFiles != build.DefaultMaxLogFiles { | ||
| if cfg.LogConfig.File.MaxLogFiles != | ||
| build.DefaultMaxLogFiles { | ||
|
|
||
| return nil, mkErr("cannot set both maxlogfiles and "+ | ||
| "logging.file.max-files", err) | ||
| } | ||
|
|
||
| cfg.LogConfig.File.MaxLogFiles = cfg.MaxLogFiles | ||
| } | ||
| if cfg.MaxLogFileSize != build.DefaultMaxLogFileSize { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| if cfg.LogConfig.File.MaxLogFileSize != | ||
| build.DefaultMaxLogFileSize { | ||
|
|
||
| return nil, mkErr("cannot set both maxlogfilesize and "+ | ||
| "logging.file.max-file-size", err) | ||
| } | ||
|
|
||
| cfg.LogConfig.File.MaxLogFileSize = cfg.MaxLogFileSize | ||
| } | ||
|
|
||
| err = cfg.LogRotator.InitLogRotator( | ||
| cfg.LogConfig.File, | ||
| filepath.Join(cfg.LogDir, defaultLogFilename), | ||
| cfg.LogCompressor, cfg.MaxLogFileSize, cfg.MaxLogFiles, | ||
| ) | ||
| if err != nil { | ||
| str := "log rotation setup failed: %v" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.