Back to course

Logging for Observability

Go (Golang) for Cloud-Native Microservices

Structured Logging

In the cloud, simple text logs are hard to search. We use Structured Logging (JSON).

Using slog (Go 1.21+):

go import "log/slog"

slog.Info("user logged in", "user_id", 42, "ip", "1.2.3.4")

This allows tools like Elasticsearch or Datadog to parse your logs easily.