ChoiceSoftware deliveryCommunity

Log message level fit

Check whether one log statement uses the right level: the level fits, it is too loud (noisy errors or warnings that wake people up), too quiet (real failures hidden at info or debug), or it should not be logged at all because of secrets or personal data, so logs and alerts stay useful.

F@f

Limits to keep in mind

Teams define levels differently; use the conventions in service_context when they are given.

The classifier sees one line; aggregated metrics or alerts elsewhere may already cover a failure that looks too quiet here.

If a secret has already been logged in production, removing the line is not enough: rotate the secret and clean the stored logs.

Problem

Log levels drift as code grows. Expected events such as a user typing a wrong password get logged as ERROR and trigger alerts, while real failures such as a payment webhook that was dropped hide at INFO or DEBUG. Some statements log tokens, passwords or full personal records. On-call engineers learn to ignore error dashboards, log costs grow, and the one line that explains an outage is buried or was never written at the right level.

Goal

Label each log statement in code review so a well-leveled line passes, a line that is too loud is moved down a level or sampled, a line that is too quiet for a real failure is raised so it reaches dashboards and alerts, and a line that leaks secrets or personal data is removed or redacted before merge, with a person deciding when the team's conventions or the impact are unclear.

Input / state

One log statement with the code around it and a short note about the service, its alerting rules and how often the line runs.

log_statement
The log call as written: level, message and the fields or variables it includes.
code_context
The code around it: what just happened, whether the error is handled, retried or returned to the caller, and what happens next.
service_context
Optional: what the service does, how often this path runs, which levels page someone or feed dashboards, and the team's logging conventions.

Decision question

ChoiceQuestion key log_level_fit

Does this log statement use the right level and content? Use level_fits when the level matches the event and its impact. Use too_loud when an expected or handled event is logged at WARN or ERROR. Use too_quiet when a real failure or data loss is logged at INFO, DEBUG or not at all. Use should_not_log when it includes secrets or unneeded personal data. Use needs_review when it is unclear.

Options

  • level_fitsThe level matches the event: DEBUG for detail useful only while investigating, INFO for normal milestones, WARN for something unexpected but handled that may need attention if it repeats, ERROR for a failure that needs action. The message says what happened and includes useful identifiers but no secrets.
  • too_loudAn expected, handled or user-caused event is logged at WARN or ERROR: invalid input, a wrong password, a 404 for a missing page, a retry that then succeeds, or a hot loop that logs the same line thousands of times per minute. It creates noise and false alerts.
  • too_quietA real failure is logged too low or swallowed: lost data, a dropped message or webhook, a failed payment or email after all retries, a broken invariant, or a caught exception logged at DEBUG or INFO with no error level, so nobody will notice it.
  • should_not_logThe line logs something that should never be in logs, whatever the level: passwords, API keys, tokens, session cookies, full card numbers, or personal data beyond what is needed, such as full addresses, health data or whole user records. Remove or redact it.

Allowed outcomes

Decided in your code from the answer and its confidence. Thresholds are yours to set and test.

  • Ask the service ownerConfidence is below your threshold, the impact of the event is unclear, the team's level conventions differ, or the line feeds compliance or audit logs.
  • Keep the log line as writtenChoice is level_fits and confidence meets your threshold.
  • Lower the level or sample the lineChoice is too_loud and confidence meets your threshold; suggest the right level or a rate limit.
  • Raise the level so it is seenChoice is too_quiet and confidence meets your threshold; suggest ERROR or WARN plus the identifiers to include.
  • Remove or redact before mergeChoice is should_not_log and confidence meets your threshold; redact the secret or personal data and rotate any leaked secret.

Example scenarios

Predefined demonstrations. No model is called; the outcome shown is an illustrative judgment.

Example state

{
  "code_context": "Login handler returns 401 to the client; the user can try again; lockout after 5 attempts is handled elsewhere",
  "log_statement": "logger.error(\"Login failed for user %s: invalid password\", user_id)",
  "service_context": "Auth service, about 2,000 failed logins per hour; ERROR lines create alerts in the on-call channel"
}

Outcome

Illustrative
Lower the level or sample the line

Choice is too_loud and confidence meets your threshold; suggest the right level or a rate limit.

Why

A user typing a wrong password is an expected, handled event; at ERROR it creates thousands of false alerts.

Using it well

  • Judge the event, not the word 'error' in the message: a handled validation error caused by the user is not an ERROR-level event for the service.
  • A retry that succeeds is usually DEBUG or INFO; the final failure after all retries is usually ERROR.
  • Any exception that is caught and not re-raised or returned must be logged at a level someone will see if it means lost work or data.
  • Secrets and personal data override everything else: choose should_not_log even if the level is correct.
  • Lines inside loops or hot request paths that run many times per second lean toward too_loud unless sampled or aggregated.
  • Prefer stable identifiers (order id, request id, user id) over whole objects; logging a full request body or user record is usually should_not_log.
  • When ERROR pages someone in this service, a line should be ERROR only if a person needs to act on it.

Request definition

POST https://api.typesafe.ai/v1/systemone
{
  "model": "jev-latest",
  "state": {
    "log_statement": "<log_statement>",
    "code_context": "<code_context>",
    "service_context": "<service_context>"
  },
  "questions": {
    "log_level_fit": {
      "type": "choice",
      "instructions": "Does this log statement use the right level and content? Use level_fits when the level matches the event and its impact. Use too_loud when an expected or handled event is logged at WARN or ERROR. Use too_quiet when a real failure or data loss is logged at INFO, DEBUG or not at all. Use should_not_log when it includes secrets or unneeded personal data. Use needs_review when it is unclear.",
      "criteria": {
        "level_fits": "The level matches the event: DEBUG for detail useful only while investigating, INFO for normal milestones, WARN for something unexpected but handled that may need attention if it repeats, ERROR for a failure that needs action. The message says what happened and includes useful identifiers but no secrets.",
        "too_loud": "An expected, handled or user-caused event is logged at WARN or ERROR: invalid input, a wrong password, a 404 for a missing page, a retry that then succeeds, or a hot loop that logs the same line thousands of times per minute. It creates noise and false alerts.",
        "too_quiet": "A real failure is logged too low or swallowed: lost data, a dropped message or webhook, a failed payment or email after all retries, a broken invariant, or a caught exception logged at DEBUG or INFO with no error level, so nobody will notice it.",
        "should_not_log": "The line logs something that should never be in logs, whatever the level: passwords, API keys, tokens, session cookies, full card numbers, or personal data beyond what is needed, such as full addresses, health data or whole user records. Remove or redact it."
      }
    }
  }
}

Request shape from the System One API reference; a Kev server accepts the same body. Replace the placeholder state with your data. Requests need your own API key or server.

Version History

v1Current Versionabout 3 hours ago@f

Initial version

Comments (0)