From abe8985caca330f1a1328fc625c6fedffa02f64e Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sun, 16 Jun 2019 00:09:06 -0700 Subject: [PATCH] Factor connection logging into one function --- internal/utils/connlogger.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/utils/connlogger.go b/internal/utils/connlogger.go index f650fd29b..271023a4e 100644 --- a/internal/utils/connlogger.go +++ b/internal/utils/connlogger.go @@ -20,6 +20,14 @@ func netLogger(n net.Network, l log.Logger) log.Logger { return l.New("net", n) } +func connLogger(c net.Conn, l log.Logger) log.Logger { + return l.New( + "connLocalPeer", c.LocalPeer(), + "connLocalAddr", c.LocalMultiaddr(), + "connRemotePeer", c.RemotePeer(), + "connRemoteAddr", c.RemoteMultiaddr()) +} + func (cl ConnLogger) Listen(n net.Network, ma ma.Multiaddr) { WithCaller(netLogger(n, cl.l)).Debug("listener starting", "addr", ma) } @@ -29,17 +37,11 @@ func (cl ConnLogger) ListenClose(n net.Network, ma ma.Multiaddr) { } func (cl ConnLogger) Connected(n net.Network, c net.Conn) { - WithCaller(netLogger(n, cl.l)).Debug("connected", - "localPeer", c.LocalPeer(), "localAddr", c.LocalMultiaddr(), - "remotePeer", c.RemotePeer(), "remoteAddr", c.RemoteMultiaddr(), - ) + WithCaller(connLogger(c, netLogger(n, cl.l))).Debug("connected") } func (cl ConnLogger) Disconnected(n net.Network, c net.Conn) { - WithCaller(netLogger(n, cl.l)).Debug("disconnected", - "localPeer", c.LocalPeer(), "localAddr", c.LocalMultiaddr(), - "remotePeer", c.RemotePeer(), "remoteAddr", c.RemoteMultiaddr(), - ) + WithCaller(connLogger(c, netLogger(n, cl.l))).Debug("disconnected") } func (cl ConnLogger) OpenedStream(n net.Network, s net.Stream) {