multi: rename and export logWriter as RootLogWriter

This commit is contained in:
Oliver Gugger 2020-05-13 15:04:57 +02:00
parent a56ca0d0cf
commit bc3909050e
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
4 changed files with 20 additions and 18 deletions

@ -971,12 +971,12 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// 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",
logWriter.SupportedSubsystems()) RootLogWriter.SupportedSubsystems())
os.Exit(0) os.Exit(0)
} }
// Initialize logging at the default logging level. // Initialize logging at the default logging level.
err = logWriter.InitLogRotator( err = RootLogWriter.InitLogRotator(
filepath.Join(cfg.LogDir, defaultLogFilename), filepath.Join(cfg.LogDir, defaultLogFilename),
cfg.MaxLogFileSize, cfg.MaxLogFiles, cfg.MaxLogFileSize, cfg.MaxLogFiles,
) )
@ -988,7 +988,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, logWriter) err = build.ParseAndSetDebugLevels(cfg.DebugLevel, RootLogWriter)
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

@ -163,7 +163,7 @@ func Main(lisCfg ListenerCfg) error {
cfg = loadedConfig cfg = loadedConfig
defer func() { defer func() {
ltndLog.Info("Shutdown complete") ltndLog.Info("Shutdown complete")
err := logWriter.Close() err := RootLogWriter.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)
} }

26
log.go

@ -47,21 +47,23 @@ import (
// //
// Loggers can not be used before the log rotator has been initialized with a // Loggers can not be used before the log rotator has been initialized with a
// log file. This must be performed early during application startup by // log file. This must be performed early during application startup by
// calling logWriter.InitLogRotator. // calling RootLogWriter.InitLogRotator.
var ( var (
logWriter = build.NewRotatingLogWriter() // RootLogWriter is the main parent log writer all sub loggers should be
// appended to.
RootLogWriter = build.NewRotatingLogWriter()
// Loggers that need to be accessible from the lnd package can be placed // Loggers that need to be accessible from the lnd package can be placed
// here. Loggers that are only used in sub modules can be added directly // here. Loggers that are only used in sub modules can be added directly
// by using the addSubLogger method. // by using the addSubLogger method.
ltndLog = build.NewSubLogger("LTND", logWriter.GenSubLogger) ltndLog = build.NewSubLogger("LTND", RootLogWriter.GenSubLogger)
peerLog = build.NewSubLogger("PEER", logWriter.GenSubLogger) peerLog = build.NewSubLogger("PEER", RootLogWriter.GenSubLogger)
rpcsLog = build.NewSubLogger("RPCS", logWriter.GenSubLogger) rpcsLog = build.NewSubLogger("RPCS", RootLogWriter.GenSubLogger)
srvrLog = build.NewSubLogger("SRVR", logWriter.GenSubLogger) srvrLog = build.NewSubLogger("SRVR", RootLogWriter.GenSubLogger)
fndgLog = build.NewSubLogger("FNDG", logWriter.GenSubLogger) fndgLog = build.NewSubLogger("FNDG", RootLogWriter.GenSubLogger)
utxnLog = build.NewSubLogger("UTXN", logWriter.GenSubLogger) utxnLog = build.NewSubLogger("UTXN", RootLogWriter.GenSubLogger)
brarLog = build.NewSubLogger("BRAR", logWriter.GenSubLogger) brarLog = build.NewSubLogger("BRAR", RootLogWriter.GenSubLogger)
atplLog = build.NewSubLogger("ATPL", logWriter.GenSubLogger) atplLog = build.NewSubLogger("ATPL", RootLogWriter.GenSubLogger)
) )
// Initialize package-global logger variables. // Initialize package-global logger variables.
@ -112,7 +114,7 @@ func init() {
func addSubLogger(subsystem string, useLoggers ...func(btclog.Logger)) { func addSubLogger(subsystem string, useLoggers ...func(btclog.Logger)) {
// Create and register just a single logger to prevent them from // Create and register just a single logger to prevent them from
// overwriting each other internally. // overwriting each other internally.
logger := build.NewSubLogger(subsystem, logWriter.GenSubLogger) logger := build.NewSubLogger(subsystem, RootLogWriter.GenSubLogger)
setSubLogger(subsystem, logger, useLoggers...) setSubLogger(subsystem, logger, useLoggers...)
} }
@ -121,7 +123,7 @@ func addSubLogger(subsystem string, useLoggers ...func(btclog.Logger)) {
func setSubLogger(subsystem string, logger btclog.Logger, func setSubLogger(subsystem string, logger btclog.Logger,
useLoggers ...func(btclog.Logger)) { useLoggers ...func(btclog.Logger)) {
logWriter.RegisterSubLogger(subsystem, logger) RootLogWriter.RegisterSubLogger(subsystem, logger)
for _, useLogger := range useLoggers { for _, useLogger := range useLoggers {
useLogger(logger) useLogger(logger)
} }

@ -5220,7 +5220,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(
logWriter.SupportedSubsystems(), " ", RootLogWriter.SupportedSubsystems(), " ",
), ),
}, nil }, nil
} }
@ -5229,7 +5229,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, logWriter) err := build.ParseAndSetDebugLevels(req.LevelSpec, RootLogWriter)
if err != nil { if err != nil {
return nil, err return nil, err
} }