$npx -y skills add ncklrs/startup-os-skills --skill logging-best-practicesExpert logging guidance based on Boris Tane's loggingsucks.com philosophy.
| 1 | # Logging Best Practices |
| 2 | |
| 3 | Expert guidance for production-grade logging based on Boris Tane's [loggingsucks.com](https://loggingsucks.com/) philosophy. |
| 4 | |
| 5 | ## Core Philosophy |
| 6 | |
| 7 | **Stop logging "what your code is doing." Start logging "what happened to this request."** |
| 8 | |
| 9 | Traditional logging is optimized for *writing*, not *querying*. Developers emit logs for immediate debugging convenience without considering how they'll be searched later. This creates massive signal-to-noise ratios at scale. |
| 10 | |
| 11 | ## The Wide Events Architecture |
| 12 | |
| 13 | Instead of scattered log statements throughout your code, build **one comprehensive event per request per service**: |
| 14 | |
| 15 | ```javascript |
| 16 | // ❌ Traditional scattered logging |
| 17 | logger.info("Request started"); |
| 18 | logger.info(`User ${userId} found`); |
| 19 | logger.info("Fetching cart"); |
| 20 | logger.debug(`Cart has ${items.length} items`); |
| 21 | logger.info("Processing payment"); |
| 22 | logger.error(`Payment failed: ${error.message}`); |
| 23 | |
| 24 | // ✅ Wide event - build throughout request, emit once |
| 25 | const event = { |
| 26 | request_id: req.id, |
| 27 | timestamp: Date.now(), |
| 28 | service: "checkout", |
| 29 | version: "2.3.1", |
| 30 | |
| 31 | user: { id: userId, tier: "premium", account_age_days: 847 }, |
| 32 | cart: { id: cartId, item_count: 3, total_cents: 15999 }, |
| 33 | payment: { method: "card", provider: "stripe", latency_ms: 234 }, |
| 34 | |
| 35 | outcome: "failure", |
| 36 | error: { type: "PaymentDeclined", code: "card_declined", retriable: true } |
| 37 | }; |
| 38 | |
| 39 | logger.info(event); |
| 40 | ``` |
| 41 | |
| 42 | ## Key Concepts |
| 43 | |
| 44 | | Concept | Definition | |
| 45 | |---------|------------| |
| 46 | | **Wide Event** | One comprehensive, context-rich log per request per service | |
| 47 | | **Cardinality** | Number of unique values (user IDs = high, HTTP methods = low) | |
| 48 | | **Dimensionality** | Count of fields per event (aim for 40+ meaningful fields) | |
| 49 | | **Tail Sampling** | Sample decisions after request completion based on outcomes | |
| 50 | |
| 51 | ## When to Apply This Skill |
| 52 | |
| 53 | - Implementing logging in new services |
| 54 | - Reviewing code with log statements |
| 55 | - Debugging production issues |
| 56 | - Designing observability strategy |
| 57 | - Migrating from printf-style to structured logging |
| 58 | - Reducing log volume while improving queryability |
| 59 | |
| 60 | ## What This Skill Provides |
| 61 | |
| 62 | 1. **Wide event patterns** for different frameworks and languages |
| 63 | 2. **Field design guidance** for high-cardinality debugging |
| 64 | 3. **Sampling strategies** that preserve signal |
| 65 | 4. **Anti-pattern detection** in existing logging code |
| 66 | 5. **Query-first thinking** for log architecture |