mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
build: apply log type flags in NewDefaultLogHandlers
So that the logging config "Disable" options and log type flags are all handled in one place. Other repo's can then re-use this nicely.
This commit is contained in:
@@ -9,8 +9,10 @@ import (
|
||||
// NewDefaultLogHandlers returns the standard console logger and rotating log
|
||||
// writer handlers that we generally want to use. It also applies the various
|
||||
// config options to the loggers.
|
||||
func NewDefaultLogHandlers(cfg *LogConfig, rotator *RotatingLogWriter) (
|
||||
btclog.Handler, btclog.Handler) {
|
||||
func NewDefaultLogHandlers(cfg *LogConfig,
|
||||
rotator *RotatingLogWriter) []btclog.Handler {
|
||||
|
||||
var handlers []btclog.Handler
|
||||
|
||||
consoleLogHandler := btclog.NewDefaultHandler(
|
||||
os.Stdout, cfg.Console.HandlerOptions()...,
|
||||
@@ -19,5 +21,18 @@ func NewDefaultLogHandlers(cfg *LogConfig, rotator *RotatingLogWriter) (
|
||||
rotator, cfg.File.HandlerOptions()...,
|
||||
)
|
||||
|
||||
return consoleLogHandler, logFileHandler
|
||||
maybeAddLogger := func(cmdOptionDisable bool, handler btclog.Handler) {
|
||||
if !cmdOptionDisable {
|
||||
handlers = append(handlers, handler)
|
||||
}
|
||||
}
|
||||
switch LoggingType {
|
||||
case LogTypeStdOut:
|
||||
maybeAddLogger(cfg.Console.Disable, consoleLogHandler)
|
||||
case LogTypeDefault:
|
||||
maybeAddLogger(cfg.Console.Disable, consoleLogHandler)
|
||||
maybeAddLogger(cfg.File.Disable, logFileHandler)
|
||||
}
|
||||
|
||||
return handlers
|
||||
}
|
||||
|
Reference in New Issue
Block a user