Skip to content

fix(logging): keep the component and apply printf formats in the app log - #10770

Merged
diegosouzapw merged 3 commits into
diegosouzapw:release/v3.8.50from
maxmad64bis:fix/log-format-console-interceptor
Aug 20, 2026
Merged

diegosouzapw merged 3 commits into
diegosouzapw:release/v3.8.50from
maxmad64bis:fix/log-format-console-interceptor

Conversation

@maxmad64bis

Copy link
Copy Markdown
Contributor

⚠️ base-red inherited: #9985

Summary

Two defects in the same formatting path of consoleInterceptor, both visible in a live app log.

extractComponent takes the first bracketed group in a message as the component name. The
in-repo tagged logger emits [LEVEL] [TAG] message (open-sse/utils/logger.ts), so every tagged
entry recorded its level as the component instead — 2,349 of 35,471 lines filed under
"component":"INFO" on a measured instance. Level tokens are now skipped, so the real tag survives.

argsToMessage joined arguments with spaces instead of formatting them, so printf strings stayed
literal with their values trailing behind, unlabelled — 4,736 lines with unsubstituted
placeholders on the same log. src/server/ws/liveServer.ts uses %s/%d deliberately, to keep
client-supplied values out of the format slot (CWE-134 hardening) — util.format is now applied
when the first argument looks like a format string, appending any surplus arguments exactly like
the previous join.

A trailing Error argument is exempted from the printf path: some call sites build their first
argument from dynamic content (a hook or tag name) that can coincidentally contain a %s-like
substring, and util.format would otherwise consume the Error as a substitution value and drop
its stack from the log.

Related Issues

  • None on file.

Validation

  • Change type: other (logging/observability)
  • Focused tests: node --test tests/unit/console-interceptor-message-fidelity.test.ts (2/2),
    npm run test:vitest (368/368)
  • npm run lint
  • Reconciled with release/v3.8.50
  • Production-code changes include a new automated test in this PR

Tests Added Or Updated

  • tests/unit/console-interceptor-message-fidelity.test.ts (new)

Coverage Notes

Touches only src/lib/consoleInterceptor.ts. Both formatting defects and the Error-swallowing
edge case are each covered by a dedicated assertion in the new test file.

Reviewer Notes

LEVEL_TOKENS is a small hardcoded set of level words, kept in sync by comment with
open-sse/utils/logger.ts's LEVELS rather than importing it: LEVELS only has 4 keys
(debug/info/warn/error) and doesn't cover WARNING/FATAL/TRACE, which also appear as
bracket tags elsewhere in the codebase.

maxmad64bis and others added 2 commits August 19, 2026 19:40
Two defects in the same formatting path of consoleInterceptor.

extractComponent took the first bracket of the message. The in-repo tagged logger
emits "[LEVEL] [TAG] message" (open-sse/utils/logger.ts), so entries were filed
under the level and the real component was dropped — the log stopped being
filterable by component, which is the point of the field. Level tokens are now
skipped; the level already travels in the entry's own field.

argsToMessage joined the arguments instead of formatting them, so printf format
strings stayed literal with their values trailing behind, unlabelled. That is not
sloppiness on the caller side: src/server/ws/liveServer.ts passes %s/%d
deliberately, to keep client-supplied values out of the format slot (CWE-134).
util.format is applied only when the first argument is a string containing a
specifier, and it appends surplus arguments exactly like the previous join, so
calls without a format string keep byte-identical output.
…ke a format string

argsToMessage() took the printf path whenever the first argument contained any
%s/%d/%i/%f/%j/%o/%O/%c substring — including dynamic content like a hook or
tag name that is not a deliberate format string. When that happened with a
trailing Error argument, util.format() consumed the Error as the substitution
value and dropped its message and stack from the app log.

Skip the printf path whenever a trailing argument is an Error, so those calls
keep the full message+stack formatting regardless of what the first
argument's text contains.
@diegosouzapw
diegosouzapw merged commit ee230fa into diegosouzapw:release/v3.8.50 Aug 20, 2026
5 checks passed
@maxmad64bis
maxmad64bis deleted the fix/log-format-console-interceptor branch September 24, 2026 21:13
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…log (diegosouzapw#10770)

Merged via merge-train (release/v3.8.50, batch1 2026-08-20) — static gates (typecheck/file-size/complexity/cognitive/changelog) green on the combined tree; test:unit reds observed in the boarded run were verified pre-existing on the pure release tip (unrelated flake), not caused by this PR. Thanks for the contribution!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants