Structured Request Logging
Use a uniform log format and pass one reqId through all related calls.
Format
[reqId] [timestamp] [level] [component] message | key=value key2=value2
Logger Design
- Component-scoped loggers (
Auth,VideoRoutes,VideoRenderWorkflow, etc). - Overloads for
(message, context)and(reqId, message, context). error()includes stack traces automatically.
Route Wrapper Pattern
Wrap route handlers with lifecycle logging:
await runRoute(logger, reqId, { method, path }, async () => {
// handler body
});
This gives:
- request-received log
- request-failed log on exception
- request-completed log with
statusanddurationMs
What to Include
- IDs:
videoId,workflowId,pickId. - Timing:
durationMs. - State transitions: previous and next status.