Skip to content
Velloreth
Technology 4 min read

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

The levels

LevelMeaningExample
TRACEthe finest detaila loop iteration
DEBUGa diagnostica variable value
INFOa normal eventa request served
WARNunexpected, not faileda retry
ERRORa failurean exception
FATALthe process cannot continuea 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

LogMetric
Recordsan eventa number
Cardinalityhighlow
Costper eventper series
Answerswhat happenedhow 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.

For the related topics, see metrics-logs-and-traces and monitoring-vs-observability. For the broader context, incident-postmortems and debugging-strategies-that-work.

Frequently asked questions

What are the standard log levels?
TRACE, DEBUG, INFO, WARN, ERROR and FATAL, in increasing severity. INFO is for a normal event, WARN is for something unexpected that did not fail, and ERROR is for a failure that needs attention. A production service usually runs at INFO and raises the level temporarily to debug.
What is a structured log?
A log line written as JSON with named fields, such as a timestamp, a level, a message and a request id, rather than a free-form string. It is queryable, so a search for a field is possible, and it is machine-parseable. A free-form string requires a regex to query.
What is a correlation id?
A unique value generated at the start of a request and included in every log line for that request, including the logs of the downstream services. It is what lets you follow one request across several services. It is often sent in a header such as X-Request-Id.
What should never be logged?
A password, a token, a session id, a full card number, a secret, and personal data that is not needed. A log is often less protected than a database, and it is copied to several systems. Redact the sensitive fields before the log is written.
What is the difference between a log and a metric?
A log records an event with the detail, and a metric records a number over time. A log answers what happened, and a metric answers how many or how fast. A high-cardinality value such as a user id belongs in a log, not in a metric label.
How long should logs be kept?
Long enough to investigate an incident and to meet a compliance requirement, which is often 30 to 90 days for an application log. A longer retention is expensive, so an archive to cheap storage is the common pattern.