Example result: Add logging that helps you debug later
AI-generated example · Logging
Updated

Add logging that helps you debug later

Good logs answer what happened during an incident. This prompt adds log lines for key steps, request IDs, timings and errors at the right levels, and never logs passwords, tokens or personal data.

text-code-useful-logging — claude — 87 words

Act as a senior engineer who has debugged many production incidents.

Code:
[PASTE]
It runs as: [e.g. an API on a server, a nightly job, a serverless function]
Logging tool: [e.g. console, Python logging, pino, or none yet]

Add logging that would let me answer "what happened?" during an incident: key steps, IDs to follow one request, timings for slow calls and clear error context. Use levels properly (debug, info, warn, error). Never log passwords, tokens or personal data. Explain what each log line would tell me.

Add a request or job ID to every log line. It lets you follow one user's journey through thousands of lines.

Get a better result

What you will get

Your code with log lines at the key steps, a request or job ID carried through, timings around slow calls and clear error context, using debug, info, warn and error properly, with a note on what each line tells you.

Common mistake

Secrets end up in the logs.

Fix: Ask it to list every field it logs and confirm none are passwords, tokens, emails or card numbers. Check request bodies especially.

Also watch for
  • Every line is info level, so the logs flood. Say how the code runs and how busy it is. Ask for debug on loops and details, info only for milestones.
  • It invents a logging library you do not use. Fill in your logging tool. If you have none, ask for the standard one for your language before adding a new dependency.
Try a variation: add structured logs

Ask for JSON log lines with fixed fields (time, level, request ID, event, duration) so your log tool can filter and graph them.

Still not right? Reply with this

Here is a real log sample from one run: [PASTE]. Could someone answer “what happened?” from this alone? If not, what is missing?

More chat & writing prompts

See all 465 →