← Back to Pull requests

Name the warning level `warn` in structured logs #7045

Closed
unknown closed this pull request without merging on Aug 18, 2026 14:54 UTC
View on GitHub
unknown unknown commented on Aug 18, 2026 14:07 UTC
Author

Problem

workerd emits structured JSON logs from two places, with two different sets of level names:

| Producer | Level names |
| --- | --- |
| JS console logs — logLevelToString() in io/worker.c++, via formatLog() in src/node/internal/internal_inspect.ts | debug info log warn error |
| Process-level logs — context.warning() / KJ_LOG, via log-schema.capnp in server/json-logger.c++ | debug info warning error fatal |

debug, info and error agree. warning was the lone outlier, so a consumer keying on warn
picks up a Worker's console.warn() but silently demotes workerd's own warnings to whatever it does
with unrecognised levels:

  • Miniflare's defaultStructuredLogsHandler tests level === "error" || level === "warn", so a

  • process warning goes to console.log instead of red console.error.
  • wrangler's handleStructuredLogs tests warn/info/debug/error and falls through to

  • logger.log, which is below the warn threshold — so --log-level=warn hides warnings entirely.
  • The Vite plugin's handler tests warn/error and falls through to logger.info.
  • Change

    Spell the level warn on the wire. The Cap'n Proto enumerant keeps mirroring
    kj::LogSeverity::WARNING; only the $Json.name annotation changes, so no C++ is affected —
    capnp's AnnotatedEnumHandler applies the annotation to both encode and decode, and
    json-logger.c++ already installs it via handleByAnnotation.

    This fixes already-released wrangler, Vite plugin and Miniflare versions on the next workerd
    bump, with no changes needed on their side.

    log-schema.capnp is consumed only by json-logger.{h,c++} and its test, and lives under
    server/, so this doesn't reach the production runtime. No compatibility flag applies: this is
    process-level CLI output, not per-Worker behaviour.

    Testing

    The level names had no coverage: json-logger-test decoded each entry with the same annotated codec
    that encoded it, which round-trips whatever the schema says. That's why the mismatch went unnoticed.

  • New JSON log level names test pins the encoded string for all five levels. It needs no captured

  • file descriptor, unlike the rest of that file, so it runs on macOS and Windows too — which lets
    the file drop its Blank test because KJ fails when 0 tests are enabled placeholder.
  • One literal "level":"warn" assertion in the existing structured-mode test, so the real

  • context.warning() path is pinned rather than just the codec.
  • Confirmed red first: {"timestamp":"0","level":"warning","context_depth":0} failed the WARNING

  • case while debug/info/error/fatal passed, confirming warning was the only outlier.
  • Verified end to end by running workerd serve on a config with structuredLogging = true and a

  • redundant compatibility flag (stacking #6980 locally so the diagnostic is a warning rather than a
    fatal error):

      {"timestamp":"1787059251355","level":"warn","source":"src/workerd/server/json-logger.c++:109","message":"service main: The compatibility flag global_navigator became the default as of 2022-03-21 so does not need to be specified anymore.","context_depth":0}
      

  • Full suite: 1635/1635 pass, 6 skipped.
  • Noticed, not addressed

  • log-schema.capnp claims contextDepth is "only included if > 0" and buildJsonLogMessage

  • guards on that, but the codec emits default primitives regardless, so every entry carries
    "context_depth":0.
  • source on process-level entries is always json-logger.c++:109 or :127 — the wrapper's own

  • __FILE__/__LINE__, not the origin. Only KJ_LOG entries get a useful value.
  • fatal has no counterpart in the console vocabulary, so it still lands at plain log level in

  • workers-sdk. It can't be aliased to error here: duplicate $Json.name values would break
    AnnotatedEnumHandler, which inserts them into a kj::HashMap. That fix belongs on the consumer
    side, along with optionally accepting "warning" so older workerd binaries stay correctly levelled.

    Diff: 506 lines (+379 / -127) across 6 files Reviewer: mar-cf Review duration: 47m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 506 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.373
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #7045"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.6% (MEDIUM) · Higher = larger blast radius
    47.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%