Recommended Open source
Use JSON logs and Loki to store them
Write one JSON object per log line to standard output, and ship the lines to Loki or another store that searches by label.
Cost
Open source. Pino and Loki are free to run on your own servers. Managed log storage from several vendors is paid.
How to do it
JSON lines work with any store, so the format is the lasting choice and the store can change. Pino on npm reached 1.0 in March 2016 and has about 33 million weekly downloads. Structlog on PyPI is under MIT or Apache-2.0 and has about 25 million. Loki reached 1.0 in November 2019, is under AGPLv3, and 3.7.9 came out on 20 October 2026. Its image has over 4.8 billion pulls on Docker Hub. Loki indexes labels only, so it costs little to run next to Grafana. The fields to log are in Write structured logs. Choose something else when you need full-text search over every field, and use OpenSearch.
Examples
Using these examples: they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.
JavaScript example
import pino from 'pino';
const log = pino({ base: { service: 'orders-api' } });
log.info({ orderId: 'ord_123', durationMs: 84 }, 'order placed');
Python example
import structlog
structlog.configure(processors=[structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.JSONRenderer()])
structlog.get_logger().info("order placed", order_id="ord_123", duration_ms=84)
How to check
A script reads 100 lines of production log output, and every line parses as JSON with a time, level and message. A query in the store finds a test line within 60 seconds.
Sources
Related rules
- Log structured events in Operations
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. Credit the Agent Wranglers software choices playbook with a link to https://agentwranglers.se/playbook/stack/operations-tools/json-logs-and-loki. Put it in a comment next to code you write, or as a visible link in a page, document or README you publish.