Logging
What is it?
Logging is recording events and messages from a running program so you can understand what it did and diagnose problems.
Explain like I'm 5
Why was it created?
When software misbehaves, you need a record of what occurred. Logging was adopted as the basic way to capture that history.
Where is it used?
- Debugging and incident response
- Audit trails
- Monitoring behavior
- Understanding production issues
Why should developers care?
Logs are the first thing engineers reach for during an incident, so good logging is essential to operating software.
How does it work?
Code emits log messages with a severity level (debug, info, warning, error). These are written to files or a central system, ideally as structured data, where they can be searched and filtered later.
Real-world example
After a checkout failure, an engineer searches the logs, finds an 'error: payment timeout' entry with the order ID, and traces the cause.
Common use cases
- Diagnosing failures
- Tracking key events
- Security and audit trails
- Feeding observability tools
Advantages
- Detailed event history
- Essential for debugging
- Supports audits
- Simple and universal
Disadvantages
- Volume and storage costs
- Noise can hide signal
- Logging secrets is a risk
- Too little or too much both hurt
When should you use it?
In every real application — log meaningful events and errors.
When should you avoid it?
Avoid logging sensitive data, and avoid excessive noise that buries useful entries.
Alternatives
Related terms
Interview questions
Beginner
- What is logging?
- What are log levels?
Intermediate
- Why prefer structured logs?
- What should you never log?
Senior
- How do you manage log volume and cost?
- How do logs fit with metrics and traces?
Common misconceptions
- "More logging is always better" — excessive logs add noise and cost, hiding what matters.
- "Logs alone give full observability" — they're one pillar alongside metrics and traces.
Fun facts
- Structured logs (e.g. JSON) are far easier to search than plain text.
- Logging is one of observability's three pillars, with metrics and traces.
Timeline
- 2010s — Centralized, structured logging becomes standard practice
Learning resources
Quick summary
Logging records a program's events and errors so you can diagnose problems and understand behavior — a core operational tool.
Cheat sheet
- Record events and errors
- Use log levels
- Prefer structured logs
- Don't log secrets; mind volume