logging: add error to udp logs

This also makes the format of UDP and HTTP logs a little more similar.
This commit is contained in:
Jimmy Zelinskie
2015-06-26 21:07:29 -04:00
parent 9a0d86610c
commit 0741df3575
3 changed files with 26 additions and 16 deletions

View File

@@ -68,19 +68,22 @@ func (s *Server) serve(listenAddr string) error {
return err
}
start := time.Now()
go func() {
response, action := s.handlePacket(buffer[:n], addr)
pool.GiveSlice(buffer)
start := time.Now()
response, action, err := s.handlePacket(buffer[:n], addr)
defer pool.GiveSlice(buffer)
duration := time.Since(start)
if len(response) > 0 {
sock.WriteToUDP(response, addr)
}
if glog.V(2) {
duration := time.Since(start)
glog.Infof("[UDP - %9s] %s %s", duration, action, addr)
if err != nil {
glog.Infof("[UDP - %9s] %s %s (%s)", duration, action, addr, err)
} else {
glog.Infof("[UDP - %9s] %s %s", duration, action, addr)
}
}
}()
}