DocsBest practices
Writing logs that help
Find problems in seconds instead of hours.
Best practices 3 min read
Good logs answer three questions: what happened, where, and for whom. Bad logs are either silent or so noisy that the real error is buried.
Do
- Prefix lines with a level: INFO, WARN, ERROR.
- Include an identifier (user, guild, request id).
- Log the start and end of important tasks.
Don't
- Log every incoming message or request.
- Print full objects that contain tokens or emails.
- Use console.log("here") style debugging in production.
Clear, searchable output
INFO command=/play guild=8823 user=1102 took=142ms
WARN rate limited route=/channels/:id/messages retry=1.2s
ERROR failed to save playlist guild=8823 reason="connection timeout"Was this article helpful?