-
Deployment
Set up structured logging you can actually search
Replace console.log spam with structured, leveled logs that are searchable when things go wrong at 2am.
Free Prompt
Set up structured logging in my app. Right now logs are console.log calls scattered around, which is fine locally and useless in production.
Do the following:
1. Pick a logger with structured (JSON) output (pino, winston, bunyan, or the equivalent for my language). Log lines should be one JSON object per line: timestamp, level, message, and structured fields for context (user id, request id, route, duration, error stack).
2. Set levels correctly: debug for local noise, info for normal operational events (request start/finish, job completed), warn for degraded-but-recovered situations, error for real failures with a full stack trace. Don't log passwords, tokens, or full request bodies at any level.
3. Attach a request id (generated per incoming request, propagated through async work) to every log line for that request. That's what makes 'find every log related to this user's failed checkout' a two-second search instead of an hour of grep.
4. Log the interesting places explicitly: request in/out, database errors, external API calls (with timing and status), job start/finish/failure, and any caught-and-swallowed exception (so it's not silent).
5. Ship logs somewhere I can query them. Most platforms have a log ingestion story; if I'm on my own metal, at least write to a rotated file and tell me how to search it. Ephemeral filesystems on serverless/PaaS lose logs on restart, so streaming to a service matters.
Don't log PII you don't need. Don't log secrets ever. The deliverable is the logger configured, request-id middleware in place, structured logs replacing console.log at the key sites, and a documented query for 'show me the last five errors' on my log destination.
What This Does / How This Helps
This replaces ad-hoc console logging with a real structured logger: JSON lines, log levels, per-request ids, and a destination you can actually query. Unstructured logs are the reason outages take four hours instead of forty minutes. When something breaks at 2am, you need to answer 'what happened to this user's request' without reading a million lines by hand. Structured logs make that a query, request ids make it fast, and shipping them off-box means they still exist after the crashed instance gets recycled.
Want to skip doing this by hand?
Fortivibe audits your app for all of the areas these prompts cover (and more).