Factor connection logging into one function

pull/1074/head
Eugene Kim 6 years ago
parent 4b6786a404
commit abe8985cac
  1. 18
      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) {

Loading…
Cancel
Save