Logging Levels: What to Log and at Which Level
A log level is a severity. Learn the levels, the structured log, the correlation id, and what must never be logged.
By Velloreth
The levels
| Level | Meaning | Example |
|---|---|---|
| TRACE | the finest detail | a loop iteration |
| DEBUG | a diagnostic | a variable value |
| INFO | a normal event | a request served |
| WARN | unexpected, not failed | a retry |
| ERROR | a failure | an exception |
| FATAL | the process cannot continue | a missing config |
A level filters the output, so a production service runs at INFO.
A temporary raise to DEBUG is how a problem is investigated.
What to log
INFO:
- A request served, with the method, the path, the status and the duration
- A job started and finished
- A user signed in
- A config loaded
WARN:
- A retry
- A deprecated call
- A slow query
- A fallback used
ERROR:
- An unhandled exception
- A failed dependency
- A validation that should not fail
- A data inconsistency
Do not log a normal event at ERROR, because it trains the reader to ignore the level.
The structured log
{
"timestamp": "2026-10-26T10:00:00Z",
"level": "INFO",
"message": "request served",
"method": "GET",
"path": "/api/posts",
"status": 200,
"duration_ms": 42,
"request_id": "8f14e45f"
}
It is queryable, so a search for a field is possible.
A free-form string requires a regex, which is slower and fragile.
A consistent field name is what makes a dashboard possible.
The correlation id
const requestId = req.headers['x-request-id'] || crypto.randomUUID();
logger.child({ requestId });
It ties the logs of one request together.
It is sent to the downstream services, so the whole trace is searchable.
A header such as X-Request-Id is the convention.
The redaction
Never log:
- A password
- A token or a session id
- A full card number
- A secret or an API key
- A personal datum that is not needed
A log is often less protected than a database, and it is copied to several systems.
A redaction list is applied before the log is written.
const REDACT = ['password', 'token', 'authorization', 'cardNumber'];
A card number is logged as the last four digits at most.
The levels in a library
A library should log at DEBUG, and the application decides the level.
A library that logs at INFO floods the application log.
A library should not configure the logger, because the application owns the configuration.
The performance
A log write is I/O, so a synchronous write in a hot path is slow.
A buffered writer batches the writes.
A log level check avoids the cost of building a message that is discarded.
if (logger.isDebugEnabled()) {
logger.debug(expensiveToString());
}
A high-volume log is expensive to store and to search.
The log versus the metric
| Log | Metric | |
|---|---|---|
| Records | an event | a number |
| Cardinality | high | low |
| Cost | per event | per series |
| Answers | what happened | how many, how fast |
A user id belongs in a log, not in a metric label, because a high cardinality explodes the metric series.
The retention
Long enough to investigate an incident and to meet a compliance requirement.
30 to 90 days is common for an application log.
An archive to cheap storage is the pattern for a longer retention.
Common mistakes
A secret in a log. A leak.
A password in a log. A leak.
A normal event at ERROR. An ignored level.
A free-form string. A hard query.
No correlation id. A hard trace.
A log in a hot loop. A slow path.
A synchronous write. A slow path.
No level check. A wasted string build.
A high-cardinality metric label. An exploded series.
No retention policy. An unbounded cost.
A quotable summary
A log level is a severity that filters the output, with INFO for a normal event, WARN for something unexpected that did not fail, and ERROR for a failure that needs attention. A structured log is JSON with named fields, which makes it queryable, and a correlation id ties the logs of one request together across the services. Never log a password, a token or a full card number, and remember that a log records an event while a metric records a number.
Related reading
For the related topics, see metrics-logs-and-traces and monitoring-vs-observability. For the broader context, incident-postmortems and debugging-strategies-that-work.