UDP is a connectionless transport-layer protocol that sends datagrams without guaranteeing delivery or ordering. It avoids connection maintenance and acknowledgment waits, making it useful when an application should keep sending despite a slow or unavailable receiver. section 7.3
Use UDP for logging when throughput and sender independence matter more than reliable delivery:
- The client sends whenever it is ready and does not wait for server acknowledgments. section 7.3
- A slow log server does not impose TCP-style back pressure on the client. section 7.3
- The application remains less affected by log-server hiccups, although UDP packets may be lost. section 7.3
UDP-based logging in Go
Create a connection with net.DialTimeout("udp", "localhost:1902", 30*time.Second), defer its closure, and pass the connection to log.New. The logger can then write ordinary and panic messages directly to the UDP endpoint. Run a compatible listener with nc -luk 1902. The timeout mainly limits address resolution and message sending rather than waiting for an acknowledgment. section 7.3
Figure 7.2 UDP log messages, showing the relative simplicity compared to TCP. Messages receive no Ack from the server.
Shows UDP log messages traveling without server acknowledgments, highlighting the protocol's simpler communication path compared with TCP. section 7.3




