Logging Levels: Prompt Options for Debug vs Production
Wrencare handles medication check-ins for 12 care homes from a single-region Node.js backend, and last month an on-call engineer spent 90 minutes chasing a failed dose record because the production logs printed only the word failed, 42 times, with no home id, no time, and no request context. The debug logs that would have answered it in seconds had been switched off months earlier, and nobody had replaced them with anything usable. The gap was not tooling. It was that the same prompt mindset had shaped every log line the app ever wrote.
Log level is a setting with consequences, and the prompt should say which one you are writing for. The table below maps a runtime context to a level, then a copy-paste prompt follows for each, then what each level costs once it reaches production. For code health more broadly, the patterns in our error handling guide decide what deserves a log at all.
Log Level Decision Table
| Runtime context | Log level | What you write | Where it hurts |
|---|---|---|---|
| Reproducing a failed check-in on a laptop | debug | Request body, variable values, the query sent | Never ship it; it would leak patient data |
| Testing a new dose-reminder job in staging | info | Job start, doses processed, total duration | Becomes background noise at production volume |
| A check-in request fails validation | warn | Home id, error code, retry count, no patient detail | Quiet enough that a slow trend goes unnoticed |
| An audit write or record update fails | error | Operation, home id, timestamps, correlation id | Alerts fire unless thresholds are set |
| The service cannot reach its database | fatal | Process state, region, last successful write | Retry loops can flood the log in seconds |
Two questions pick the row. Is this event normal operation, or a deviation someone must act on? Normal events belong at info or below. And would this line contain anything you would not put on a screen in a care home office? If yes, it stays at debug and never reaches production.
Choosing a Level per Environment
The same code ships to every environment, so the level is really a target, not a constant. On a developer laptop, debug is the whole point: you want the request body and the values in flight so you can see the failure. In staging, info is the working level, because the job’s start, count, and duration tell you whether a new dose-reminder runs cleanly without drowning the view in variable dumps.
Production is where the discipline pays. Warn, error, and fatal should be the only levels you routinely keep, and each needs a reason to exist. A validation failure is a warn because it is expected and handled. A failed audit write is an error because a record may be missing and someone must check it. A lost database connection is fatal because the process cannot do its job at all.
The mistake is to treat the level as a verbosity dial rather than a signal. Turning everything to info in production does not give you more information; it gives you more lines, and the failed dose record from last month would still have been buried alongside ten thousand healthy check-ins. Set the level by what deserves a human response, then keep the two or three events that matter loud. For the review habit that catches missing context before it ships, see the checks in our code review prompts.
One more distinction earns its keep. Levels are not the same as channels. A warn line written to the application log and a warn line sent to an alerting channel are the same severity but two very different costs, and a care-home backend that pages the on-call engineer on every warn will train everyone to ignore the pager within a week. Decide the level first, then decide separately whether that level leaves the machine at all.
Prompts for Each Level
Debug level for local work. Verbose, temporary, never deployed.
Add debug logging to a Node.js medication check-in handler for local troubleshooting only. Goal: reproduce a failed dose record. For each step in the handler, log the home id, the medication id, the request body, and the result of the validation function. Wrap every log call so it only fires when NODE_ENV equals development. Add a comment above each block saying it must not run in production. Do not log any patient name or date of birth.Warn and error levels for production. Structured, minimal, and actionable.
Rewrite the production logging for a Node.js medication check-in service. Use structured JSON logs. On validation failure, log at warn with fields: home_id, medication_id, error_code, retry_count. On a failed audit write, log at error with fields: operation, home_id, timestamp, correlation_id, and a fixed error string. Never log patient name, date of birth, or free-text notes. Explain in one line per field why it is safe to store in production.Redaction and review prompt. Catch leaks before the deploy.
Audit this list of log statements for a care-home backend. For each one, state whether it should run in production, which level it should use, and whether it contains personal or health data. Flag any line that logs a name, an address, a date of birth, or a free-text clinical note. Return a table with the original line, the verdict, and the safer replacement. Assume a single-region deployment.Redaction is cheaper to design than to retrofit. A care-home backend that names every field it is willing to log, once, spends five minutes on the rule and saves a data-protection conversation later. Add the correlation id to every warn and error line so you can follow one failed check-in across services, and let that id, not the patient, be what ties the story together.
What Production Logging Costs
Debug logging costs you privacy. A request body for a medication check-in can contain a patient name, and a care-home backend that writes it to a shared log has created a record you cannot easily delete. Keep debug strictly local and gate it on the environment variable, so a copy of the code cannot spill patient data by accident.
Info logging costs you attention. Every healthy check-in written to info makes the one that failed harder to find, which is the exact reason the 90-minute hunt happened. Log the aggregate, not each event: one line per job run with the count and duration beats twelve thousand lines that say nothing.
Error and fatal logging cost you a pager if you get the thresholds wrong. A database outage that retries every second can emit thousands of fatal lines a minute, and a naive alert on any fatal line will wake someone for a problem that is already being handled. Set a threshold, then let the flood be one incident rather than a thousand.
The practical rule for Wrencare is short. Debug never ships. Info counts, it does not narrate. Warn and error carry the fields an engineer needs at 2 a.m. and nothing that identifies a patient. Set that once and the next failed dose record becomes a two-minute read instead of a 90-minute hunt.
Count the cost in lines, not just in money. A single-region service that writes one info line per check-in produces thousands of lines a day for 12 care homes, and the storage adds up faster than the review time. Aggregating healthy events into one line per job run keeps the volume flat while the homes grow, which matters because a log that grows with traffic is a log nobody will read by the time it is needed.
Sources & Notes
These prompts describe a Node.js medication check-in backend for a nursing-home operator, but the level-versus-environment split applies to any service that handles personal data. Wrencare, its 12 care homes, the single-region deployment, and the 90-minute investigation are an illustrative scenario, not a real company or incident. Logging libraries such as pino and winston are named as common examples; check your own framework’s current behaviour, and confirm any data-protection rules that apply to the health data you log.
