Logging standards for clean, parseable logs
Great logs make debugging faster, on-call calmer, and audits painless. We standardized how we log across projects so messages are consistent, traceable, machine-friendly, and safe. Use this playbook during implementation and PR reviews.
1. Timestamps: always ISO-8601
All log timestamps are ISO-8601. This is enforced by our logging configuration, so no manual formatting is needed. It keeps time unambiguous and sortable, so logs line up correctly across services and tools.
2. Make logs traceable with correlation IDs
Every related message should carry a correlation or trace ID so you can follow a request or job end-to-end. Our config attaches this automatically. For app-level support, use a request or async scope correlation ID.
3. Name your logger instances clearly
Use unique, descriptive logger names that reflect the module or script emitting messages.
In normal modules
Define the logger as a module-level “global”, and treat the variable like a constant:
LOGGER = logging.getLogger(__name__)In support or one-off scripts
Use an explicit, readable name. The helper handles date-stamped log files:
from support.helpers.logs import get_logger
LOGGER = get_logger("data_export_monthly")4. Log format: machine-parseable (JSON-like)
Write messages in a structure that machines can parse and humans can scan.
Pattern: a short action sentence plus a single structured payload object.
LOGGER.info(
"Docket status updated. %(payload)s",
{"payload": {
"docket_id": str(docket.id),
"status_id": str(status.id),
"firm_id": str(firm.id),
"update_date": datetime_instance.isoformat(),
}},
)5. Message consistency and context
Each log line should be unique in text and context across the project. Prefer clear, action-oriented phrasing:
Do
“Official deadline dates calculated.” with a single, meaningful payload
Don't
“Calculating…” then “Calculated.”: two lines with little value
6. Choose the right level
| Level | When to use it |
|---|---|
DEBUG |
Log at this level about anything that happens in the program. This is mostly used during debugging, and I’d advocate trimming down the number of debug statements before entering the production stage, so that only the most meaningful entries are left, and can be activated during troubleshooting. |
INFO |
Log at this level all actions that are user-driven, or system-specific, and all notable events that are not considered an error |
WARNING |
Log at this level all events that could potentially become an error. For instance, if one database call took more than a predefined time, or if an in-memory cache is near capacity. This will allow proper automated alerting, and during troubleshooting, will allow us to better understand how the system was behaving before the failure. |
ERROR |
Log every error condition at this level. That can be API calls that return errors or internal error conditions. |
CRITICAL |
Too bad, it’s doomsday. Use this very scarcely; this shouldn’t happen a lot in a real program. Usually, logging at this level signifies the end of the program. For instance, if a network daemon can’t bind a network socket, logging at this level and exiting is the only sensible thing to do. |
7. Avoid excessive or redundant logging
Prefer one clear, contextual line over many trivial ones. If a line does not help you debug or alert, delete it.
Every log line has a cost. It is shipped, indexed and stored, and someone has to read past it during an incident. When a service logs too much, the line that explains a failure is buried under hundreds that say nothing, alerts start firing on noise, and the log bill grows faster than the traffic.
A few habits keep the volume useful:
- Log state changes, not steps. One line when a job starts and one when it ends, with its payload, says more than a line per iteration.
- Keep loops quiet. Inside a loop over thousands of records, count and summarize (“422 records synced, 3 skipped”) instead of logging each one.
- Log an error once, where it is handled. Logging the same exception at every layer it passes through turns one failure into a wall of duplicates.
- Leave tracing to DEBUG. Step-by-step detail belongs at the DEBUG level, off in production and switched on only while you troubleshoot.
Before adding a line, ask what you would do if you saw it in production. If the answer is nothing, it does not need to be there.
8. Never log personal or identifiable data
Example: “good” vs “bad”
Good
LOGGER.info(
"Payment captured. %(payload)s",
{"payload": {
"payment_id": str(payment.id),
"order_id": str(order.id),
"amount_cents": payment.amount_cents,
"captured_at": timezone.now().isoformat(),
}},
)Bad
# Leaks PII, unstructured, hard to trace or search
LOGGER.info("Payment for John Smith captured!")PR review checklist
- Timestamp is ISO-8601 using config
- Correlation ID is present along the request or job path
LOGGERis module level and uniquely named for scripts- Messages follow “action + payload” and payload is JSON-like, with strings for UUIDs and
.isoformat()for datetimes - Messages are unique, concise, and useful
- Levels are being correctly used (DEBUG, INFO, WARNING, ERROR, …)
- No personal or identifiable data, IDs only
Quick starter for Django
import logging
from uuid import uuid4
from django.utils import timezone
LOGGER = logging.getLogger(__name__) # module-level constant
def run():
batch_id = str(uuid4())
LOGGER.info("Batch started. %(payload)s", {"payload": {
"batch_id": batch_id,
"started_at": timezone.now().isoformat(),
}})
# ...work...
LOGGER.info("Batch finished. %(payload)s", {"payload": {
"batch_id": batch_id,
"duration_ms": 842,
"result": "ok",
}})For correlation IDs in web requests, add middleware such as django-guid to attach a request-scoped ID and include it in all emitted records.
Use this setup to trace a run with one batch_id, keep lines concise and consistent, and avoid PII while staying easy to parse across services.
Related articles

Article · 13 min read
Django zero downtime deployment: best practices and implementation guide
Keep a Django app running smoothly through updates, migrations and system changes.
13 min read

Article · 5 min read
Building privacy-first Django applications: model-based anonymization
Embed privacy rules in your models so developers own the anonymization of user data.
5 min read




