A logging service receives log messages over a network, aggregates logs from applications or clustered servers, and often stores them centrally. This approach suits cloud deployments where local storage may be ephemeral. section 7.2.1
A practical network logging setup combines:
- A TCP endpoint that accepts streamed text messages. section 7.2.1
- Go's net and log packages to write ordinary log output to the connection. section 7.2.1
- Channels and buffering to reduce message loss when streaming is error-prone. section 7.2.1
Simulate a logging service
Run `nc -lk 1902` to listen continuously on TCP port 1902 and print incoming messages. A Go client can call `net.Dial("tcp", "localhost:1902")`, create `log.New(conn, "example ", flags)`, and send messages with `Println`. section 7.2.1
Listing 7.7 Network log client
package main
import (
"log"
"net"
)
func main() {
conn, err := net.Dial("tcp", "localhost:1902") #1
if err != nil {
panic("Failed to connect to localhost:1902")
}
defer conn.Close() #2
f := log.Ldate | log.Lshortfile #3
logger := log.New(conn, "example ", f) #4
logger.Println("This is a regular message.")
logger.Panicln("This is a panic.") #5
}
Inspect the complete Go client that connects to the simulated service, defers connection cleanup, configures log metadata, and emits messages. section 7.2.1

