← All notes

Structured logging with log/slog

Answer: log/slog, added in Go 1.21, brings structured logging to the standard library.

Quick start

import "log/slog"

slog.Info("hello, world", "user", "jba")

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Warn("slow request", "path", "/api", "ms", 812)

JSON output looks like {"time":"...","level":"INFO","msg":"hello, world","user":"jba"}.

Concepts

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Structured Logging with slog - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), slog package - log/slog - Go Packages, CC BY 4.0 (go.dev text).

Cite this

Permanent ID: iil:note:zjdgwzq3

iinventedlight. 2026. "Structured logging with log/slog." iinventedlight Library, iil:note:zjdgwzq3, version of 2026-11-04. https://iinventedlight.com/library/notes/go-structured-logging-slog/. License: CC-BY-4.0.

@misc{iil_note_zjdgwzq3,
  author = {{iinventedlight}},
  title = {{Structured logging with log/slog}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/go-structured-logging-slog/},
  note = {Permanent ID iil:note:zjdgwzq3. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/go-structured-logging-slog.md.