go-slog

Implement structured logging in Go services with log/slog.

Updated Feb 24, 2026
One-click install
npx skills add https://github.com/brian861105/codex-skills --skill go-slog
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-slog
Source: https://github.com/brian861105/codex-skills/tree/main/go-slog
Command: npx skills add https://github.com/brian861105/codex-skills --skill go-slog

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often suffer from inconsistent, ad-hoc logging that makes debugging and tracing requests difficult. This Skill promotes using the standard library log/slog to create structured, context-aware logs across services, handlers, CLIs, and background jobs.

Core Features & Use Cases

  • Structured logging with slog fields to capture rich context.
  • Attach logger to context or pass *slog.Logger explicitly to functions.
  • Level-aware logging with Debug, Info, Warn, and Error for clear severity control.
  • Consistent guidance for aligning logs with request IDs, user identifiers, and component names.

Quick Start

Initialize a logger with slog and attach it to your context, then use its level methods to emit structured logs at the call sites.

Frequently Asked Questions about go-slog

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement structured logging in Go services using slog?▼

Structured logging in Go uses the standard log/slog package to create context-aware logs. You initialize a slog.Logger, attach it to your context, and emit structured fields with Debug, Info, Warn, or Error methods for consistent observability.

What is the best way to attach a slog logger to a Go context?▼

The best way to attach a slog logger is to store the *slog.Logger instance within the standard Go context. This allows handlers and background jobs to extract consistent logging fields like request IDs without passing the logger explicitly through every function.

Can I use log/slog for background jobs and CLIs in Go?▼

Yes, log/slog is fully suitable for background jobs and CLIs in Go. It provides level-aware logging with Debug, Info, Warn, and Error methods to ensure consistent severity control and traceability across all production workflows.

Why do my Go service logs lack traceability across requests?▼

Go service logs lack traceability due to inconsistent, ad-hoc logging. Implementing standardized structured logging with log/slog aligns your logs with request IDs, user identifiers, and component names for reliable debugging.

Do I need external dependencies to use slog for Go observability?▼

No external dependencies are required. The log/slog package is part of the standard Go library, allowing you to implement context-rich observability and structured logging directly within your services.