INSTRUCTIONS
Apply Dave Cheney's logging philosophy: simplify ruthlessly, handle errors properly, and log only what matters.
Core Principles
Only Two Log Levels Matter
- Info: For operators/users—things they need to know during normal operation
- Debug: For developers—controlled per-package during development
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."
- Don't log an error AND return it (causes duplicate logs up the stack)
- Don't log errors in library code (caller decides what to do)
- Do let errors bubble up to where they can be meaningfully handled
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:
- The error chain ends here—no caller to return to
- The user receives a generic message (for security/UX)
- Operators need the full error details for debugging
// 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.
Review Checklist
When reviewing or writing logging code:
Anti-Patterns to Avoid
// 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")
Structured Logging
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),
)
Reference
Based on: Let's talk about logging by Dave Cheney (2015)
1---2name: logging-33description: 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 log+return pattern, discussing log levels, or designing error handling strategies.4---5
6# INSTRUCTIONS
7
8Apply Dave Cheney's logging philosophy: simplify ruthlessly, handle errors properly, and log only what matters.
9
10## Core Principles
11
121. **Only Two Log Levels Matter**
13 - **Info**: For operators/users—things they need to know during normal operation
14 - **Debug**: For developers—controlled per-package during development
15
162. **Eliminate Unnecessary Levels**
17 | Level | Verdict | Reason |
18 |-------|---------|--------|
19 | Warning | Remove | "Nobody reads warnings"—either it's an error or info |
20 | Fatal | Avoid | Bypasses `defer`, prevents cleanup. Let errors bubble to `main()` |
21 | Error | Rethink | If handled, it's info. If not handled, return it to caller |
22
23 **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.
24
253. **The Golden Rule of Error Logging**
26 > "You should either handle the error, or pass it back to the caller."
27
28 - **Don't** log an error AND return it (causes duplicate logs up the stack)
29 - **Don't** log errors in library code (caller decides what to do)
30 - **Do** let errors bubble up to where they can be meaningfully handled
31
324. **Terminal Error Handlers: When Error Level IS Appropriate**
33
34 At the boundary where errors become **user-facing unexpected failures** (e.g., 5xx responses), error-level logging is correct:
35
36 - The error chain ends here—no caller to return to
37 - The user receives a generic message (for security/UX)
38 - Operators need the full error details for debugging
39
40 ```go
41 // At HTTP handler boundary - error level is appropriate
42 if err != nil {
43 log.Error("unexpected failure",
44 "error", err,
45 "request_id", requestID,
46 )
47 http.Error(w, "Internal Server Error", http.StatusInternalServerError)
48 return
49 }
50 ```
51
52 **This is NOT the same as logging mid-stack**—this is the terminal handler where errors are finally consumed, not propagated.
53
54## Review Checklist
55
56When reviewing or writing logging code:
57
58- [ ] Is this log statement for users (info) or developers (debug)?
59- [ ] Am I logging an error AND returning it? (Remove the log)
60- [ ] Is this a terminal handler (5xx boundary)? (Error level is appropriate here)
61- [ ] Is this a warning? (Convert to info or error, or remove)
62- [ ] Is this `Fatal`/`panic` in library code? (Return error instead)
63- [ ] Does this log message help the operator understand system state?
64
65## Anti-Patterns to Avoid
66
67```go
68// BAD: Log and return (duplicate logs)
69if err != nil {
70 log.Error("failed to connect", err)
71 return err
72}
73
74// GOOD: Just return (let caller decide)
75if err != nil {
76 return fmt.Errorf("connect: %w", err)
77}
78
79// BAD: Warning that nobody will act on
80log.Warn("connection pool running low")
81
82// GOOD: Either info (if expected) or error (if action needed)
83log.Info("connection pool at 80% capacity")
84```
85
86## Structured Logging
87
88When logging is appropriate, prefer structured formats:
89
90```go
91// Prefer structured fields over string interpolation
92log.Info("request completed",
93 "method", r.Method,
94 "path", r.URL.Path,
95 "duration", time.Since(start),
96)
97```
98
99## Reference
100
101Based on: [Let's talk about logging](https://dave.cheney.net/2015/11/05/lets-talk-about-logging) by Dave Cheney (2015)