---
source: https://iinventedlight.com/library/notes/go-structured-logging-slog.md
title: "Structured logging with log/slog"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (go.dev text); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Go"
tags: ['go', 'logging', 'slog', 'observability']
sources:
  - id: S1
    title: "Structured Logging with slog - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/slog
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "slog package - log/slog - Go Packages"
    publisher: The Go Authors (go.dev)
    url: https://pkg.go.dev/log/slog
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# Structured logging with log/slog

**Answer:** `log/slog`, added in Go 1.21, brings structured logging to the standard library.

## Quick start

```go
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

- **Levels:** Debug, Info, Warn, Error.
- For more control over the output format, create a logger with a different handler. (S2)

## Claims
- id: C1
  claim: log/slog in Go 1.21 brings structured logging to the standard library.
  source: S1
  evidence: "The new log/slog package in Go 1.21 brings structured logging to the standard"
- id: C2
  claim: Structured logs use key-value pairs.
  source: S1
  evidence: "library. Structured logs use key-value pairs so they can be parsed, filtered,"
- id: C3
  claim: Everything becomes a key-value pair in text output.
  source: S1
  evidence: "Everything has been turned into a key-value pair, with strings quoted as needed to preserve"
- id: C4
  claim: For more control over output, create a logger with a different handler.
  source: S2
  evidence: "For more control over the output format, create a logger with a different handler."

## Sources
- [S1] Structured Logging with slog - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/slog . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] slog package - log/slog - Go Packages. The Go Authors (go.dev). https://pkg.go.dev/log/slog . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
