mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-26 09:44:46 -07:00
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:
15
udp/udp.go
15
udp/udp.go
@@ -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)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user