Structured Logging
Production API logs should be machine-readable and searchable.
Useful fields include timestamp, severity, service name, environment, request ID, trace ID, HTTP method, route, status code, duration, user or tenant identifier where appropriate, and error classification.
Never log passwords, access tokens, session cookies, or sensitive personal information unnecessarily.
Logging the route template such as /users/:id is generally more useful than logging millions of unique URLs.
Structured Request Log
{
"level": "info",
"requestId": "req_123",
"method": "GET",
"route": "/users/:id",
"status": 200,
"durationMs": 23
}💡 Structured fields allow logs to be searched and aggregated without parsing human-readable strings.