logging-best-practices
Logging best practices focused on wide events (canonical log lines) for powerful debugging and analytics
Skill by boristane
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/wearedevpunks-logging-best-practices
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, data
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
logging-best-practices- Description
- Logging best practices focused on wide events (canonical log lines) for powerful debugging and analytics
- License
- MIT
- Metadata
- author: boristane · version: 1.0.0
- Instructions
- 120 lines in SKILL.md · view on GitHub
Files (5)
- SKILL.md
- context.md · rules/
- pitfalls.md · rules/
- structure.md · rules/
- wide-events.md · rules/
SKILL.md (first lines)
# Logging Best Practices Skill
Version: 1.0.0
## Purpose
This skill provides guidelines for implementing effective logging in applications. It focuses on **wide events** (also called canonical log lines) - a pattern where you emit a single, context-rich event per request per service, enabling powerful debugging and analytics.
## When to Apply
Apply these guidelines when:
- Writing or reviewing logging code
- Adding console.log, logger.info, or similar
- Designing logging strategy for new services
- Setting up logging infrastructure
## Core Principles
### 1. Wide Events (CRITICAL)
Emit **one context-rich event per request per service**. Instead of scattering log lines throughout your handler, consolidate everything into a single structured event emitted at request completion.
```typescript
const wideEvent: Record<string, unknown> = {
method: 'POST',
path: '/checkout',
requestId: c.get('requestId'),
timestamp: new Date().toISOString(),
};
try {
const user = await getUser(c.get('userId'));
wideEvent.user = { id: user.id, subscription: user.subscription };
const cart = await getCart(user.id);
wideEvent.cart = { total_cents: cart.total, item_count: cart.items.length };
wideEvent.status_code = 200;
wideEvent.outcome = 'success';
return c.json({ success: true });
} catch (error) {
wideEvent.status_code = 500;
wideEvent.outcome = 'error';
wideEvent.error = { message: error.message, type: error.name };
throw error;
} finally {
wideEvent.duration_ms = Date.now() - startTime;
logger.info(wideEvent);
}
```
### 2. High Cardinality & Dimensionality (CRITICAL)
Include fields with high cardinality (user IDs, request IDs - millions of unique values) and high dimensionality (many fields per event). This enables querying by specific users and answering questions you haven't anticipated yet.
### 3. Business Context (CRITICAL)
Always include business context: user subscription tier, cart value, feature flags, account age. The goal is to know "a premium customer couldn't complete a $2,499 purchase" not just "checkout failed."
### 4. Environment Characteristics (CRITICAL)
Include environment and deployment info in every event: commit hash, service version, region, instance ID. This enables correlating issues with deployments and identifying region-specific problems.
### 5. Single Logger (HIGH)
Use one logger instance configured at startup and import it everywhere. This ensures consistent formatting and automatic environment context.
### 6. Middleware Pattern (HIGH)
Use middleware to handle wide event infrastructure (timing, status, environment, emission). Handlers should only add business context.
### 7. Structure & Consistency (HIGH)
- Use JSON format consistently
- Maintain consistent field names across services
- Simplify to two log levels: `info` and `error`
- Never log unstructured strings
## Anti-Patterns to Avoid
1. **Scattered logs**: Multiple console.log() calls per request
2. **Multiple loggers**: Different logger instances in different files
3. **Missing environment context**: No commit hash or deployment info
4. **Missing business context**: Logging technical details without user/business data
5. **Unstructured strings**: `console.log('something happened')` instead of structured data
6. **Inconsistent schemas**: Different field names across services
## Guidelines
### Wide Events (`rules/wide-events.md`)
- Emit one wide event per service hop
- Include all relevant context
- Connect events with request ID
- Emit at request completion in finally block
### Context (`rules/context.md`)
- Support high cardinality fields (user_id, request_id)
- Include high dimensionality (many fields)
- Always include business context
- Always include environment characteristics (commit_hash, version, region)
### Structure (`rules/structure.md`)
- Use a single logger throughout the codebase
- Use middleware for consistent wide events
- Use JSON format
- Maintain consistent schema
- Simplify to info and error levels
- Never log unstructured strings
### Common Pitfalls (`rules/pitfalls.md`)
- Avoid multiple log lines per request
- Design for unknown unknowns
- Always propagate request IDs across services
References:
- [Logging Sucks](https://loggingsucks.com)
- [Observability Wide Events 101](https://boristane.com/blog/observability-wide-events-101/)
- [Stripe - Canonical Log Lines](https://stripe.com/blog/canonical-log-lines)From wearedevpunks/skills, MIT.
More from wearedevpunks/skills
- 0.587score
ask-hi
wearedevpunks
Explain how the Harness Intelligence (HI) Baseline works.
SkillAFreshness: A★ 1Claude Code +9 - 0.587score
hi-cli
wearedevpunks
Operates the Harness Intelligence CLI (`hi`, alias `hint`) through init, update, diff, check, tools, report, upgrade, operator-skill, and post-command flows.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
docs-onboarding
wearedevpunks
Onboard an existing project into the scaffolded Harness wiki by inspecting code, docs and backlog, closing reconstruction decisions, then handing accepted…
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
agent-browser
wearedevpunks
Automate web interactions with agent-browser using Lightpanda by default.
SkillAFreshness: A★ 1Claude Code +9 - 0.582score
break-ui
wearedevpunks
Try to break a piece of UI by feeding it worst-case data — long names, unbreakable emails, one-letter names, missing fields, huge counts, zero items, long…
SkillAFreshness: A★ 1Claude Code +9 - 0.582score
debug-agent
wearedevpunks
Systematic evidence-based debugging using runtime logs.
SkillAFreshness: A★ 1Claude Code +9 - 0.576score
rule-authoring
wearedevpunks
Maintain project-owned Codebase Rules after `hi init` or `hi update`.
SkillAFreshness: A★ 1Claude Code +9 - 0.547score
write-graph-based-skills
wearedevpunks
Write graph-based skills as Durable Workflow Graphs.
SkillBFreshness: B★ 1Claude Code +9 - 0.547score
backend-domain-structure
wearedevpunks
Organize backend code into domain-first layers with thin transport entrypoints, platform composition, external integrations, and feature-owned business…
SkillBFreshness: B★ 1Claude Code +9 - 0.542score
writing-shape
wearedevpunks
Chooses the final structure for a public-facing article, guide, or docs page from fragments and beats.
SkillBFreshness: B★ 1Claude Code +9 - 0.542score
writing-beats
wearedevpunks
Turns fragments or raw material into an ordered journey of reader-facing beats.
SkillBFreshness: B★ 1Claude Code +9 - 0.542score
writing-fragments
wearedevpunks
Mines raw writing material into a durable fragments document.
SkillBFreshness: B★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 2
- Open issues
- 0
- Last commit (this folder)
- Apr 30, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0.0
- License
- MIT
- Repository
- github.com/wearedevpunks/skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from boristane
Cite this page
logging-best-practices skill. Agent Mart. https://agentmart.dev/skills/wearedevpunks-logging-best-practices (last updated 2026-10-24)