mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
config: add logging config options
This commit adds config options so that users can for both the console logger and the file logger set the following things: - disable the logger - omit timestamps from log lines.
This commit is contained in:
38
build/config.go
Normal file
38
build/config.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package build
|
||||||
|
|
||||||
|
import "github.com/btcsuite/btclog/v2"
|
||||||
|
|
||||||
|
// 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."`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultLogConfig returns the default logging config options.
|
||||||
|
func DefaultLogConfig() *LogConfig {
|
||||||
|
return &LogConfig{
|
||||||
|
Console: &LoggerConfig{},
|
||||||
|
File: &LoggerConfig{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoggerConfig holds options for a particular logger.
|
||||||
|
//
|
||||||
|
//nolint:lll
|
||||||
|
type LoggerConfig struct {
|
||||||
|
Disable bool `long:"disable" description:"Disable this logger."`
|
||||||
|
NoTimestamps bool `long:"no-timestamps" description:"Omit timestamps from log lines."`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandlerOptions returns the set of btclog.HandlerOptions that the state of the
|
||||||
|
// config struct translates to.
|
||||||
|
func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption {
|
||||||
|
var opts []btclog.HandlerOption
|
||||||
|
if cfg.NoTimestamps {
|
||||||
|
opts = append(opts, btclog.WithNoTimestamp())
|
||||||
|
}
|
||||||
|
|
||||||
|
return opts
|
||||||
|
}
|
||||||
26
config.go
26
config.go
@@ -499,6 +499,7 @@ type Config struct {
|
|||||||
// hooked up to.
|
// hooked up to.
|
||||||
SubLogMgr *build.SubLoggerManager
|
SubLogMgr *build.SubLoggerManager
|
||||||
LogRotator *build.RotatingLogWriter
|
LogRotator *build.RotatingLogWriter
|
||||||
|
LogConfig *build.LogConfig `group:"logging" namespace:"logging"`
|
||||||
|
|
||||||
// networkDir is the path to the directory of the currently active
|
// networkDir is the path to the directory of the currently active
|
||||||
// network. This path will hold the files related to each different
|
// network. This path will hold the files related to each different
|
||||||
@@ -738,6 +739,7 @@ func DefaultConfig() Config {
|
|||||||
ServerPingTimeout: defaultGrpcServerPingTimeout,
|
ServerPingTimeout: defaultGrpcServerPingTimeout,
|
||||||
ClientPingMinWait: defaultGrpcClientPingMinWait,
|
ClientPingMinWait: defaultGrpcClientPingMinWait,
|
||||||
},
|
},
|
||||||
|
LogConfig: build.DefaultLogConfig(),
|
||||||
WtClient: lncfg.DefaultWtClientCfg(),
|
WtClient: lncfg.DefaultWtClientCfg(),
|
||||||
HTTPHeaderTimeout: DefaultHTTPHeaderTimeout,
|
HTTPHeaderTimeout: DefaultHTTPHeaderTimeout,
|
||||||
}
|
}
|
||||||
@@ -1402,18 +1404,26 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
|
|||||||
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var logCfg = cfg.LogConfig
|
||||||
consoleLogHander = btclog.NewDefaultHandler(os.Stdout)
|
consoleLogHandler := btclog.NewDefaultHandler(
|
||||||
logHandlers []btclog.Handler
|
os.Stdout, logCfg.Console.HandlerOptions()...,
|
||||||
)
|
)
|
||||||
|
logFileHandler := btclog.NewDefaultHandler(
|
||||||
|
cfg.LogRotator, logCfg.File.HandlerOptions()...,
|
||||||
|
)
|
||||||
|
|
||||||
|
var logHandlers []btclog.Handler
|
||||||
|
maybeAddLogger := func(cmdOptionDisable bool, handler btclog.Handler) {
|
||||||
|
if !cmdOptionDisable {
|
||||||
|
logHandlers = append(logHandlers, handler)
|
||||||
|
}
|
||||||
|
}
|
||||||
switch build.LoggingType {
|
switch build.LoggingType {
|
||||||
case build.LogTypeStdOut:
|
case build.LogTypeStdOut:
|
||||||
logHandlers = []btclog.Handler{consoleLogHander}
|
maybeAddLogger(logCfg.Console.Disable, consoleLogHandler)
|
||||||
case build.LogTypeDefault:
|
case build.LogTypeDefault:
|
||||||
logHandlers = []btclog.Handler{
|
maybeAddLogger(logCfg.Console.Disable, consoleLogHandler)
|
||||||
consoleLogHander,
|
maybeAddLogger(logCfg.File.Disable, logFileHandler)
|
||||||
btclog.NewDefaultHandler(cfg.LogRotator),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !build.SuportedLogCompressor(cfg.LogCompressor) {
|
if !build.SuportedLogCompressor(cfg.LogCompressor) {
|
||||||
|
|||||||
@@ -970,6 +970,19 @@
|
|||||||
; Instructs lnd to encrypt the private key using the wallet's seed.
|
; Instructs lnd to encrypt the private key using the wallet's seed.
|
||||||
; tor.encryptkey=false
|
; tor.encryptkey=false
|
||||||
|
|
||||||
|
[logging]
|
||||||
|
|
||||||
|
; Disable logging to stdout and stderror.
|
||||||
|
; logging.console.disable=false
|
||||||
|
|
||||||
|
; Don't add timestamps to logs written to stdout and stderr.
|
||||||
|
; logging.console.no-timestamps=false
|
||||||
|
|
||||||
|
; Disable logging to the standard LND log file.
|
||||||
|
; logging.file.disable=false
|
||||||
|
|
||||||
|
; Don't add timestamps to logs written to the standard LND log file.
|
||||||
|
; logging.file.no-timestamps=false
|
||||||
|
|
||||||
[watchtower]
|
[watchtower]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user