Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peer: Use a dedicated ping logger #210

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}))
}
Expand Down
10 changes: 10 additions & 0 deletions peer/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ 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.
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
Expand Down
Loading