
Structured Logging in Production: Stop Using console.log
Structured Logging in Production: Stop Using console.log Your production logs are a wall of unstructured text. Grep fails. Debugging takes hours. You need structured logging. The Problem User login failed for john@example.com Error processing payment Connection timeout after 30s Which user? Which payment? Which service timed out? Unstructured logs cannot answer these questions. Structured Logging with Pino import pino from " pino " ; const logger = pino ({ level : process . env . LOG_LEVEL || " info " }); // Instead of: console.log("User login failed for " + email) // Do: logger.warn({ userId, email, reason }, "Login failed") Output: {"level":40,"time":"2026-03-21T...","userId":"u_123","email":"john@example.com","reason":"invalid_password","msg":"Login failed"} Request Context Middleware Every log in a request should include requestId, method, path, userId: app . use (( req , res , next ) => { req . log = logger . child ({ requestId : crypto . randomUUID (), method : req . method , pat
Continue reading on Dev.to DevOps
Opens in a new tab


