config+lnd+rpcserver: use log writer from cfg

This commit is contained in:
Oliver Gugger 2020-05-25 18:22:41 +02:00
parent 32b04b7ac3
commit 70772ab99b
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
3 changed files with 17 additions and 6 deletions

View File

@ -250,6 +250,10 @@ type Config struct {
DB *lncfg.DB `group:"db" namespace:"db"` DB *lncfg.DB `group:"db" namespace:"db"`
// LogWriter is the root logger that all of the daemon's subloggers are
// hooked up to.
LogWriter *build.RotatingLogWriter
// registeredChains keeps track of all chains that have been registered // registeredChains keeps track of all chains that have been registered
// with the daemon. // with the daemon.
registeredChains *chainRegistry registeredChains *chainRegistry
@ -360,6 +364,7 @@ func DefaultConfig() Config {
}, },
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry, MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation, MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
LogWriter: build.NewRotatingLogWriter(),
DB: lncfg.DefaultDB(), DB: lncfg.DefaultDB(),
registeredChains: newChainRegistry(), registeredChains: newChainRegistry(),
} }
@ -928,15 +933,21 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
cfg.registeredChains.PrimaryChain().String(), cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(activeNetParams.Name)) normalizeNetwork(activeNetParams.Name))
// A log writer must be passed in, otherwise we can't function and would
// run into a panic later on.
if cfg.LogWriter == nil {
return nil, fmt.Errorf("log writer missing in config")
}
// Special show command to list supported subsystems and exit. // Special show command to list supported subsystems and exit.
if cfg.DebugLevel == "show" { if cfg.DebugLevel == "show" {
fmt.Println("Supported subsystems", fmt.Println("Supported subsystems",
RootLogWriter.SupportedSubsystems()) cfg.LogWriter.SupportedSubsystems())
os.Exit(0) os.Exit(0)
} }
// Initialize logging at the default logging level. // Initialize logging at the default logging level.
err = RootLogWriter.InitLogRotator( err = cfg.LogWriter.InitLogRotator(
filepath.Join(cfg.LogDir, defaultLogFilename), filepath.Join(cfg.LogDir, defaultLogFilename),
cfg.MaxLogFileSize, cfg.MaxLogFiles, cfg.MaxLogFileSize, cfg.MaxLogFiles,
) )
@ -948,7 +959,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
} }
// Parse, validate, and set debug log level(s). // Parse, validate, and set debug log level(s).
err = build.ParseAndSetDebugLevels(cfg.DebugLevel, RootLogWriter) err = build.ParseAndSetDebugLevels(cfg.DebugLevel, cfg.LogWriter)
if err != nil { if err != nil {
err = fmt.Errorf("%s: %v", funcName, err.Error()) err = fmt.Errorf("%s: %v", funcName, err.Error())
_, _ = fmt.Fprintln(os.Stderr, err) _, _ = fmt.Fprintln(os.Stderr, err)

2
lnd.go
View File

@ -190,7 +190,7 @@ type rpcListeners func() ([]*ListenerWithSignal, func(), error)
func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
defer func() { defer func() {
ltndLog.Info("Shutdown complete") ltndLog.Info("Shutdown complete")
err := RootLogWriter.Close() err := cfg.LogWriter.Close()
if err != nil { if err != nil {
ltndLog.Errorf("Could not close log rotator: %v", err) ltndLog.Errorf("Could not close log rotator: %v", err)
} }

View File

@ -5295,7 +5295,7 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
if req.Show { if req.Show {
return &lnrpc.DebugLevelResponse{ return &lnrpc.DebugLevelResponse{
SubSystems: strings.Join( SubSystems: strings.Join(
RootLogWriter.SupportedSubsystems(), " ", r.cfg.LogWriter.SupportedSubsystems(), " ",
), ),
}, nil }, nil
} }
@ -5304,7 +5304,7 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
// Otherwise, we'll attempt to set the logging level using the // Otherwise, we'll attempt to set the logging level using the
// specified level spec. // specified level spec.
err := build.ParseAndSetDebugLevels(req.LevelSpec, RootLogWriter) err := build.ParseAndSetDebugLevels(req.LevelSpec, r.cfg.LogWriter)
if err != nil { if err != nil {
return nil, err return nil, err
} }