From 61333d2a75c5218fce635fd378e30b42739d6492 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Mon, 25 Mar 2024 11:13:05 -0300 Subject: [PATCH] peer: Use a dedicated ping logger This switches the peer to log ping/pong messages using a separate logger with a dedicated subsystem tag. This is useful when running in debug mode for extended periods of time, as ping messages are generally useless but repeat constantly, needlessly growing the size of log files and making debug harder. --- log.go | 1 + peer/brontide.go | 10 ++++++++-- peer/log.go | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/log.go b/log.go index d027c122c0..62a0464fb2 100644 --- a/log.go +++ b/log.go @@ -139,6 +139,7 @@ func SetupLoggers(root *build.RotatingLogWriter, interceptor signal.Interceptor) AddSubLogger(root, "AUTO", interceptor, automation.UseLogger) AddSubLogger(root, "PGDB", interceptor, postgres.UseLogger) AddSubLogger(root, "LCCH", interceptor, localchans.UseLogger) + AddSubLogger(root, "PING", interceptor, peer.UsePingLogger) AddSubLogger(root, "LNWL", interceptor, lnwallet.UseLogger) AddSubLogger(root, "DISC", interceptor, discovery.UseLogger) diff --git a/peer/brontide.go b/peer/brontide.go index 91b55394f9..65b4cc4fad 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -1753,7 +1753,13 @@ func (p *Brontide) logWireMessage(msg lnwire.Message, read bool) { summaryPrefix = "Sending" } - peerLog.Debugf("%v", newLogClosure(func() string { + logger := peerLog + switch msg.(type) { + case *lnwire.Ping, *lnwire.Pong: + logger = pingLog + } + + logger.Debugf("%v", newLogClosure(func() string { // Debug summary of message. summary := messageSummary(msg) if len(summary) > 0 { @@ -1781,7 +1787,7 @@ func (p *Brontide) logWireMessage(msg lnwire.Message, read bool) { prefix = "writeMessage to" } - peerLog.Tracef(prefix+" %v: %v", p, newLogClosure(func() string { + logger.Tracef(prefix+" %v: %v", p, newLogClosure(func() string { return spew.Sdump(msg) })) } diff --git a/peer/log.go b/peer/log.go index dfdd372592..9735f477e6 100644 --- a/peer/log.go +++ b/peer/log.go @@ -8,14 +8,20 @@ import ( // peerLog is a logger that is initialized with the slog.Disabled logger. var peerLog slog.Logger +// pingLog is a logger that is used to log sent and received ping/pong +// messages. +var pingLog slog.Logger + // The default amount of logging is none. func init() { UseLogger(build.NewSubLogger("PEER", nil)) + UseLogger(build.NewSubLogger("PING", nil)) } // DisableLog disables all logging output. func DisableLog() { UseLogger(slog.Disabled) + UsePingLogger(slog.Disabled) } // UseLogger uses a specified Logger to output package logging info. @@ -23,6 +29,10 @@ func UseLogger(logger slog.Logger) { peerLog = logger } +func UsePingLogger(logger slog.Logger) { + pingLog = logger +} + // logClosure is used to provide a closure over expensive logging operations // so they aren't performed when the logging level doesn't warrant it. type logClosure func() string