Guide logging practices based on Dave Cheney's minimalist philosophy. Use when adding log.Info/Debug/Error/Warn/Fatal calls, reviewing logging code, handling errors with the log+return pattern, discussing log levels, or designing error-handling strategies.
Apply Dave Cheney's logging philosophy: simplify ruthlessly, handle errors properly, and log only what matters.
Only Two Log Levels Matter
Eliminate Unnecessary Levels
| Level | Verdict | Reason |
|-------|---------|--------|
| Warning | Remove | "Nobody reads warnings"—either it's an error or info |
| Fatal | Avoid | Bypasses defer, prevents cleanup. Let errors bubble to main() |
| Error | Rethink | If handled, it's info. If not handled, return it to caller |
Exception: Warnings from runtimes and external libraries should be logged at warning level. You don't control these sources, and their warnings often signal deprecations or upcoming breaking changes that operators need to track.
The Golden Rule of Error Logging
"You should either handle the error, or pass it back to the caller."
Terminal Error Handlers: When Error Level IS Appropriate
At the boundary where errors become user-facing unexpected failures (e.g., 5xx responses), error-level logging is correct:
// At HTTP handler boundary - error level is appropriate
if err != nil {
log.Error("unexpected failure",
"error", err,
"request_id", requestID,
)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
This is NOT the same as logging mid-stack—this is the terminal handler where errors are finally consumed, not propagated.
When reviewing or writing logging code:
Fatal/panic in library code? (Return error instead)// BAD: Log and return (duplicate logs)
if err != nil {
log.Error("failed to connect", err)
return err
}
// GOOD: Just return (let caller decide)
if err != nil {
return fmt.Errorf("connect: %w", err)
}
// BAD: Warning that nobody will act on
log.Warn("connection pool running low")
// GOOD: Either info (if expected) or error (if action needed)
log.Info("connection pool at 80% capacity")
When logging is appropriate, prefer structured formats:
// Prefer structured fields over string interpolation
log.Info("request completed",
"method", r.Method,
"path", r.URL.Path,
"duration", time.Since(start),
)
Based on: Let's talk about logging by Dave Cheney (2015)
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer