---
source: https://iinventedlight.com/library/notes/go-slog.md
title: "log/slog: structured logging in the Go standard library"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); CC-BY-4.0 (The Go Blog); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, log/slog package reference; The Go Blog, Structured Logging with slog. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-slog"
tags: [go, slog, logging, structured-logging]
client: Librarian
sources:
  - id: S1
    title: "log/slog package reference"
    publisher: Go
    url: https://pkg.go.dev/log/slog
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "Structured Logging with slog"
    publisher: The Go Blog
    url: https://go.dev/blog/slog
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# log/slog: structured logging in the Go standard library
**Answer:** Package slog provides structured logging: each record has a message, a level, and key-value attributes. A Logger builds a Record and hands it to a Handler. The log/slog package in Go 1.21 brings structured logging to the standard library.

## Records, loggers, and handlers

In slog, a log record carries a message, a severity level, and other attributes expressed as key-value pairs.

Info and Error are methods for reporting events of interest.

Each Logger is associated with a Handler, which receives the Record and decides what to do with it.

Top-level helpers such as Info and Error call the corresponding methods on a default Logger.

A log record consists of a time, a level, a message, and key-value pairs.

## Why the standard library grew a structured logger

Go 1.21 introduced log/slog so structured logging would live in the standard library.

Key-value pairs are the point: they can be parsed, filtered, searched, and analyzed quickly and reliably.

The older log package has been present since Go's first release, but the annual survey kept ranking structured logging high.

## Text and JSON handlers

TextHandler writes the record as key=value text.

For JSON output, install the built-in JSONHandler instead.

Anyone can write a handler by implementing the slog.Handler interface.

## See also

- [go-fmt](https://iinventedlight.com/library/notes/go-fmt/)
- [go-os-exec](https://iinventedlight.com/library/notes/go-os-exec/)

## Claims

- id: C1
  claim: slog records include a message, a level, and key-value attributes.
  source: S1
  evidence: "log records include a message, a severity level"

- id: C2
  claim: Each Logger is associated with a Handler.
  source: S1
  evidence: "Each Logger is associated with a Handler"

- id: C3
  claim: Top-level functions such as Info use a default Logger.
  source: S1
  evidence: "There is a default Logger accessible through top-level functions"

- id: C4
  claim: Go 1.21 added log/slog to the standard library.
  source: S2
  evidence: "The new log/slog package in Go 1.21 brings structured logging"

- id: C5
  claim: Structured logs use key-value pairs.
  source: S2
  evidence: "Structured logs use key-value pairs"

- id: C6
  claim: JSONHandler is the built-in handler for JSON output.
  source: S2
  evidence: "install the built-in JSONHandler instead"

## Sources

- [S1] log/slog package reference. Go. https://pkg.go.dev/log/slog . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] Structured Logging with slog. The Go Blog. https://go.dev/blog/slog . License: CC-BY-4.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, log/slog package reference; The Go Blog, Structured Logging with slog. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
