My Blog

My WordPress Blog

My Blog

My WordPress Blog

Structured Logging

Structured logging involves logging in a format that makes it easy to search and analyze logs. JSON is a common structured logging format.

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
), transports: [
new winston.transports.Console()
] }); logger.info('User login', { userId: 123, username: 'john_doe' });

Structured logs are easy to query and analyze with tools like Elasticsearch, Kibana, or log aggregators.

Structured Logging

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top