Skip to content
Back to skills

Golang Logging

ASecurity

Standards for structured logging and observability in Golang. Use when adding structured logging or tracing to Go services.

  • 549 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 6, 2026
developmentgoperformance

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned June 6, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill golang-logging --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Golang Logging?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Golang Logging
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-golang-logging/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-golang-logging)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: golang-logging
description: Standards for structured logging and observability in Golang. Use when adding structured logging or tracing to Go services.
metadata:
  triggers:
    files:
    - 'go.mod'
    - 'pkg/logger/**'
    keywords:
    - logging
    - slog
    - structured logging
    - zap
---
# Golang Logging Standards

## **Priority: P1 (STANDARD)**

## Principles

- **Structured Logging**: Use JSON or structured text. Readable by machines and humans.
- **Leveled Logging**: Debug, Info, Warn, Error.
- **Contextual**: Include correlation IDs (TraceID, RequestID) in logs.
- **No `log.Fatal`**: Avoid terminating app inside libraries. Return error instead. Only `main` should exit.

## Libraries

- **`log/slog` (Recommended)**: Stdlib since Go 1.21. Fast, structured, zero-dep.
- **Zap (`uber-go/zap`)**: High performance, good if pre-1.21 or extreme throughput needed.
- **Zerolog**: Zero allocation, fast JSON logger.

## Workflow: Set Up Structured Logging with slog

1. Create JSON handler at startup in `main()`
2. Optionally wrap in middleware to inject request-scoped attributes
3. Use `slog.With()` to add correlation IDs per request
4. Pass logger via context or dependency injection

See [slog setup and usage examples](references/slog-patterns.md)

## References

- [Slog Patterns](references/slog-patterns.md)

## Anti-Patterns

- **No fmt.Println in production**: Use slog or zap for structured, leveled logging.
- **No log.Fatal in libraries**: Return errors; only main() should call os.Exit.
- **No unstructured log strings**: Include correlation IDs and structured fields via slog.Attr.

Files in this skill

  • SKILL.md1.6 KB
  • evals/evals.json1.6 KB
  • references/slog-patterns.md1.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.