Commit 8fe0a1c
committed
docs(go): add Section 7 - Logging (slog default + backend decision matrix)
- 210-go.mdc: add a dedicated "Logging" section covering the modern
Go logging story. Default for new code is log/slog (stdlib since
1.21); JSON handler with AddSource and slog.LevelVar for runtime
level control; pass *slog.Logger via DI
- Three calling conventions ordered by safety: loose key-value
(error-prone, compiles cleanly with mistyped keys / odd argument
counts), context-accepting *Context variants (recommended; required
for trace correlation), LogAttrs typed-only (safest, compile-time
type-checked)
- otelslog bridge for first-class OpenTelemetry logs that carry the
active span trace and span IDs (requires *Context call variants
with an active span)
- LogValuer pattern for centralized redaction of sensitive types so
call sites cannot leak by accident
- Decision matrix for when to swap the slog backend (only with
profiling evidence): slog stdlib default; phuslu/log as backend
for ~2.7x throughput; zerolog native for max throughput; zap
native for extensibility/test observers; charmbracelet/log for
CLI output; do not start new code on logrus
- Footguns documented: zerolog as slog backend re-encodes WithAttrs
per call (~46x slower than zerolog native); zerolog chain without
Msg/Send drops + leaks pooled Event; zap.SugaredLogger adds 1
alloc per call; slog ships no TRACE/FATAL by default
- Library landscape one-liner table with stars + benchmark numbers
(phuslu/log ~25 ns; zerolog ~25 ns; zap ~51 ns; slog ~101 ns;
logrus ~9 us; charmbracelet ~16 us)
- Add sloglint to the CI Gates (Non-Negotiable) section so the
loose key-value form cannot silently produce malformed entries
- Renumber subsequent sections (8-17) since the Logging section is
inserted at 7. Fixes a pre-existing duplicate "## 8" between
Troubleshooting and CI/CD Integration along the way
- skills/go-rust-systems/SKILL.md: add a "Go Logging - Default Stack"
section mirroring the rule's calling-convention guidance, otelslog
bridge, LogValuer redaction, decision matrix, footguns, and the
required CI lint. Cross-link to the rule for full rationale
- Source: https://www.dash0.com/guides/golang-logging-libraries
(April 2026 benchmarks, captured here without external dependency)
Closes the gap between code samples that already used slog and the
absence of any explicit "use slog as default; here is when and why
to swap" guidance.1 parent bc988b2 commit 8fe0a1c
2 files changed
Lines changed: 212 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1435 | 1435 | | |
1436 | 1436 | | |
1437 | 1437 | | |
| 1438 | + | |
1438 | 1439 | | |
1439 | 1440 | | |
1440 | 1441 | | |
| |||
1624 | 1625 | | |
1625 | 1626 | | |
1626 | 1627 | | |
1627 | | - | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
1628 | 1764 | | |
1629 | 1765 | | |
1630 | 1766 | | |
| |||
1886 | 2022 | | |
1887 | 2023 | | |
1888 | 2024 | | |
1889 | | - | |
| 2025 | + | |
1890 | 2026 | | |
1891 | 2027 | | |
1892 | 2028 | | |
| |||
1920 | 2056 | | |
1921 | 2057 | | |
1922 | 2058 | | |
1923 | | - | |
| 2059 | + | |
1924 | 2060 | | |
1925 | 2061 | | |
1926 | 2062 | | |
| |||
2000 | 2136 | | |
2001 | 2137 | | |
2002 | 2138 | | |
2003 | | - | |
| 2139 | + | |
2004 | 2140 | | |
2005 | 2141 | | |
2006 | 2142 | | |
| |||
2185 | 2321 | | |
2186 | 2322 | | |
2187 | 2323 | | |
2188 | | - | |
| 2324 | + | |
2189 | 2325 | | |
2190 | 2326 | | |
2191 | 2327 | | |
| |||
2352 | 2488 | | |
2353 | 2489 | | |
2354 | 2490 | | |
2355 | | - | |
| 2491 | + | |
2356 | 2492 | | |
2357 | 2493 | | |
2358 | 2494 | | |
| |||
2501 | 2637 | | |
2502 | 2638 | | |
2503 | 2639 | | |
2504 | | - | |
| 2640 | + | |
2505 | 2641 | | |
2506 | 2642 | | |
2507 | 2643 | | |
| |||
2620 | 2756 | | |
2621 | 2757 | | |
2622 | 2758 | | |
2623 | | - | |
| 2759 | + | |
2624 | 2760 | | |
2625 | 2761 | | |
2626 | 2762 | | |
| |||
2755 | 2891 | | |
2756 | 2892 | | |
2757 | 2893 | | |
2758 | | - | |
| 2894 | + | |
2759 | 2895 | | |
2760 | 2896 | | |
2761 | 2897 | | |
| |||
2787 | 2923 | | |
2788 | 2924 | | |
2789 | 2925 | | |
2790 | | - | |
| 2926 | + | |
2791 | 2927 | | |
2792 | 2928 | | |
2793 | 2929 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
208 | 274 | | |
209 | 275 | | |
210 | 276 | | |
| |||
0 commit comments