1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

libnetwork: improve consistency in log messages

- Make sure all log messages have the `[resolver]` prefix
- Use `logrus.WithError()` consistently
- Improve information included in some logs

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-10-13 12:30:51 +02:00
parent a80c450fb3
commit d86a331fa4
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -158,7 +158,7 @@ func (r *resolver) Start() error {
r.server = s r.server = s
go func() { go func() {
if err := s.ActivateAndServe(); err != nil { if err := s.ActivateAndServe(); err != nil {
logrus.WithError(err).Error("error starting packetconn dns server") logrus.WithError(err).Error("[resolver] failed to start PacketConn DNS server")
} }
}() }()
@ -166,7 +166,7 @@ func (r *resolver) Start() error {
r.tcpServer = tcpServer r.tcpServer = tcpServer
go func() { go func() {
if err := tcpServer.ActivateAndServe(); err != nil { if err := tcpServer.ActivateAndServe(); err != nil {
logrus.WithError(err).Error("error starting tcp dns server") logrus.WithError(err).Error("[resolver] failed to start TCP DNS server")
} }
}() }()
return nil return nil
@ -389,7 +389,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
} }
if err != nil { if err != nil {
logrus.Error(err) logrus.WithError(err).Errorf("[resolver] failed to handle query: %s (%s) from %s", name, dns.TypeToString[query.Question[0].Qtype], extConn.LocalAddr().String())
return return
} }
@ -400,7 +400,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
resp = new(dns.Msg) resp = new(dns.Msg)
resp.SetRcode(query, dns.RcodeServerFailure) resp.SetRcode(query, dns.RcodeServerFailure)
if err := w.WriteMsg(resp); err != nil { if err := w.WriteMsg(resp); err != nil {
logrus.WithError(err).Error("Error writing dns response") logrus.WithError(err).Error("[resolver] error writing dns response")
} }
return return
} }
@ -467,7 +467,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// Timeout has to be set for every IO operation. // Timeout has to be set for every IO operation.
if err := extConn.SetDeadline(time.Now().Add(extIOTimeout)); err != nil { if err := extConn.SetDeadline(time.Now().Add(extIOTimeout)); err != nil {
logrus.WithError(err).Error("Error setting conn deadline") logrus.WithError(err).Error("[resolver] error setting conn deadline")
} }
co := &dns.Conn{ co := &dns.Conn{
Conn: extConn, Conn: extConn,
@ -497,7 +497,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// client can retry over TCP // client can retry over TCP
if err != nil && (resp == nil || !resp.Truncated) { if err != nil && (resp == nil || !resp.Truncated) {
r.forwardQueryEnd() r.forwardQueryEnd()
logrus.Debugf("[resolver] read from DNS server failed, %s", err) logrus.WithError(err).Debugf("[resolver] failed to read from DNS server")
continue continue
} }
r.forwardQueryEnd() r.forwardQueryEnd()
@ -554,7 +554,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
} }
if err = w.WriteMsg(resp); err != nil { if err = w.WriteMsg(resp); err != nil {
logrus.Errorf("[resolver] error writing resolver resp, %s", err) logrus.WithError(err).Errorf("[resolver] failed to write resolver response")
} }
} }