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 contextLog levelWhat you writeWhere it hurts
Reproducing a failed check-in on a laptopdebugRequest body, variable values, the query sentNever ship it; it would leak patient data
Testing a new dose-reminder job in staginginfoJob start, doses processed, total durationBecomes background noise at production volume
A check-in request fails validationwarnHome id, error code, retry count, no patient detailQuiet enough that a slow trend goes unnoticed
An audit write or record update failserrorOperation, home id, timestamps, correlation idAlerts fire unless thresholds are set
The service cannot reach its databasefatalProcess state, region, last successful writeRetry 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.

声明:1.本站所有文章,如无特殊说明或标注,均为本站原创发布。本网站中【文本生成/文生图】使用了DeeSseek人工智能生成内容技术, 算法来源说明:本网站未自行开发、训练或部署深度合成算法,所使用的人工智能算法来自:DeepSeek、Chatgpt、Google Gemini。 2.为了网站加载速度优化,本站预览图片进行压缩处理,所以有些不是太清晰,并不影响AI提示词生图、AI设计等内容。3.任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。--GUUNN.COM