multi: rename and export logWriter as RootLogWriter
This commit is contained in:
parent
a56ca0d0cf
commit
bc3909050e
@ -971,12 +971,12 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
||||
// Special show command to list supported subsystems and exit.
|
||||
if cfg.DebugLevel == "show" {
|
||||
fmt.Println("Supported subsystems",
|
||||
logWriter.SupportedSubsystems())
|
||||
RootLogWriter.SupportedSubsystems())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Initialize logging at the default logging level.
|
||||
err = logWriter.InitLogRotator(
|
||||
err = RootLogWriter.InitLogRotator(
|
||||
filepath.Join(cfg.LogDir, defaultLogFilename),
|
||||
cfg.MaxLogFileSize, cfg.MaxLogFiles,
|
||||
)
|
||||
@ -988,7 +988,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
||||
}
|
||||
|
||||
// Parse, validate, and set debug log level(s).
|
||||
err = build.ParseAndSetDebugLevels(cfg.DebugLevel, logWriter)
|
||||
err = build.ParseAndSetDebugLevels(cfg.DebugLevel, RootLogWriter)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%s: %v", funcName, err.Error())
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
|
2
lnd.go
2
lnd.go
@ -163,7 +163,7 @@ func Main(lisCfg ListenerCfg) error {
|
||||
cfg = loadedConfig
|
||||
defer func() {
|
||||
ltndLog.Info("Shutdown complete")
|
||||
err := logWriter.Close()
|
||||
err := RootLogWriter.Close()
|
||||
if err != nil {
|
||||
ltndLog.Errorf("Could not close log rotator: %v", err)
|
||||
}
|
||||
|
26
log.go
26
log.go
@ -47,21 +47,23 @@ import (
|
||||
//
|
||||
// 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
|
||||
// calling logWriter.InitLogRotator.
|
||||
// calling RootLogWriter.InitLogRotator.
|
||||
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
|
||||
// here. Loggers that are only used in sub modules can be added directly
|
||||
// by using the addSubLogger method.
|
||||
ltndLog = build.NewSubLogger("LTND", logWriter.GenSubLogger)
|
||||
peerLog = build.NewSubLogger("PEER", logWriter.GenSubLogger)
|
||||
rpcsLog = build.NewSubLogger("RPCS", logWriter.GenSubLogger)
|
||||
srvrLog = build.NewSubLogger("SRVR", logWriter.GenSubLogger)
|
||||
fndgLog = build.NewSubLogger("FNDG", logWriter.GenSubLogger)
|
||||
utxnLog = build.NewSubLogger("UTXN", logWriter.GenSubLogger)
|
||||
brarLog = build.NewSubLogger("BRAR", logWriter.GenSubLogger)
|
||||
atplLog = build.NewSubLogger("ATPL", logWriter.GenSubLogger)
|
||||
ltndLog = build.NewSubLogger("LTND", RootLogWriter.GenSubLogger)
|
||||
peerLog = build.NewSubLogger("PEER", RootLogWriter.GenSubLogger)
|
||||
rpcsLog = build.NewSubLogger("RPCS", RootLogWriter.GenSubLogger)
|
||||
srvrLog = build.NewSubLogger("SRVR", RootLogWriter.GenSubLogger)
|
||||
fndgLog = build.NewSubLogger("FNDG", RootLogWriter.GenSubLogger)
|
||||
utxnLog = build.NewSubLogger("UTXN", RootLogWriter.GenSubLogger)
|
||||
brarLog = build.NewSubLogger("BRAR", RootLogWriter.GenSubLogger)
|
||||
atplLog = build.NewSubLogger("ATPL", RootLogWriter.GenSubLogger)
|
||||
)
|
||||
|
||||
// Initialize package-global logger variables.
|
||||
@ -112,7 +114,7 @@ func init() {
|
||||
func addSubLogger(subsystem string, useLoggers ...func(btclog.Logger)) {
|
||||
// Create and register just a single logger to prevent them from
|
||||
// overwriting each other internally.
|
||||
logger := build.NewSubLogger(subsystem, logWriter.GenSubLogger)
|
||||
logger := build.NewSubLogger(subsystem, RootLogWriter.GenSubLogger)
|
||||
setSubLogger(subsystem, logger, useLoggers...)
|
||||
}
|
||||
|
||||
@ -121,7 +123,7 @@ func addSubLogger(subsystem string, useLoggers ...func(btclog.Logger)) {
|
||||
func setSubLogger(subsystem string, logger btclog.Logger,
|
||||
useLoggers ...func(btclog.Logger)) {
|
||||
|
||||
logWriter.RegisterSubLogger(subsystem, logger)
|
||||
RootLogWriter.RegisterSubLogger(subsystem, logger)
|
||||
for _, useLogger := range useLoggers {
|
||||
useLogger(logger)
|
||||
}
|
||||
|
@ -5220,7 +5220,7 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
|
||||
if req.Show {
|
||||
return &lnrpc.DebugLevelResponse{
|
||||
SubSystems: strings.Join(
|
||||
logWriter.SupportedSubsystems(), " ",
|
||||
RootLogWriter.SupportedSubsystems(), " ",
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
@ -5229,7 +5229,7 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
|
||||
|
||||
// Otherwise, we'll attempt to set the logging level using the
|
||||
// specified level spec.
|
||||
err := build.ParseAndSetDebugLevels(req.LevelSpec, logWriter)
|
||||
err := build.ParseAndSetDebugLevels(req.LevelSpec, RootLogWriter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user