logging

Implement minimal structured logging with Info and Debug levels in Go applications.

6|Updated Dec 28, 2023
One-click install
npx skills add https://github.com/staticWagomU/dotfiles --skill logging-staticwagomu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging
Source: https://github.com/staticWagomU/dotfiles/tree/main/config/claude/skills/logging
Command: npx skills add https://github.com/staticWagomU/dotfiles --skill logging-staticwagomu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamline logging to focus on meaningful events, reduce log noise, and enforce consistent error handling.

Core Features & Use Cases

  • Two primary log levels: Info for operators, Debug for developers.
  • Golden rule of error logging: avoid log-then-return duplication; propagate errors when appropriate.
  • Terminal vs mid-stack logging: differentiate where to place logs and what to log.
  • Structured logging guidance: use structured fields for context.

Quick Start

Apply the logging philosophy to current code by auditing a module and adjusting log statements accordingly.

Frequently Asked Questions about logging

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

FAQPage Schema
What is structured logging in Go and when should I use it?

Structured logging in Go uses key-value fields to add context to log entries, making them easier to query and filter. It is needed when you require clear operator-facing information and developer-focused debugging across packages and handlers.

How do I avoid duplicate error logs in Go applications?

To avoid duplicate error logs in Go, follow the golden rule of error logging: do not log an error and then return it from the same function. Propagate errors up the call stack and log them only at the terminal or top-level handler.

What are the best practices for choosing Go log levels?

Best practices for Go log levels dictate using only two primary levels: Info for operators to monitor application state, and Debug for developers to trace internal execution. This minimalist approach reduces log noise and focuses on meaningful events.

How do I implement contextual logging for HTTP handlers and background workers?

Implement contextual logging by attaching structured fields to your logs within HTTP handlers and background workers. This provides specific request or task details, ensuring the logs deliver actionable context without duplicate entries.

Where should I place log statements in a Go call stack?

Differentiate between terminal and mid-stack logging when placing log statements in Go. Log terminal errors at the top level where they are handled, and use mid-stack logs sparingly for debug-level tracing to avoid duplication.