liveBook · Manning

Logging service

As explained in Go in Practice, Second Edition

A logging service is a network-accessible system that receives, aggregates, and often stores log messages from applications.

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

How Go in Practice, Second Edition covers it

How deep it goes
Demonstrates TCP streaming, Go client construction, Netcat simulation, and buffering for reliability; stops short of service internals.
Examples
Uses Netcat on port 1902 and a Go client that sends regular and panic log messages.
What it assumes
Assumes basic Go logging and networking familiarity while introducing network destinations through a small runnable example.
What you can do after
Build it from scratch with Go's networking and logging packages, then improve delivery reliability with channels and buffering.
How it connects
Connects network logging with TCP, channels, buffering, Docker, virtual machines, Logstash, Heka, and event streams.

Also explained in

Compare how 2 books explain logging service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.