Observability Glossary

Structured Logging

Linkedin icon
Reddit icon

Structured logging is a practice of logging where log messages are formatted in a structured way, usually as JSON or key-value pairs, as opposed to plain text strings. By structuring log messages, it becomes easier to parse and analyze log data.

For example, instead of a plain text log message like User with ID 123 failed to log in, a structured log message might look like {"event": "failed_login", "user_id": 123}. This makes it easier to search, filter, and aggregate log data using log management solutions.

One of the benefits of structured logging is that it provides a standardized way to record logs, making it easier to build dashboards, create alerts, and troubleshoot errors and defects.

In JavaScript, you can be implement structured logging using libraries like Winston or Bunyan:

const winston = require('winston');

const logger = winston.createLogger({
  format: winston.format.json(),
  transports: [
    new winston.transports.Console()
  ]
});

logger.info('User login failed', { user_id: 123, error: 'Invalid credentials' });

Once you've implemented structured logging you're just one step away from distributed tracing which adds the latency dimension to your logs.

Explore related concepts
Start resolving issues today.
Without the hassle.