Skip to content

Commit

Permalink
fix(ext/node): fix formatting of debug logs (#27772)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jan 22, 2025
1 parent c930e13 commit 773825a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
7 changes: 2 additions & 5 deletions ext/node/polyfills/internal/util/debuglog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials

import { inspect } from "ext:deno_node/internal/util/inspect.mjs";

// `debugImpls` and `testEnabled` are deliberately not initialized so any call
// to `debuglog()` before `initializeDebugEnv()` is called will throw.
let debugImpls: Record<string, (...args: unknown[]) => void>;
Expand Down Expand Up @@ -49,10 +47,9 @@ function debuglogImpl(
if (debugImpls[set] === undefined) {
if (enabled) {
emitWarningIfNeeded(set);
debugImpls[set] = function debug(...args: unknown[]) {
const msg = args.map((arg) => inspect(arg)).join(" ");
debugImpls[set] = function debug(msg, ...args: unknown[]) {
// deno-lint-ignore no-console
console.error("%s %s: %s", set, String(Deno.pid), msg);
console.error("%s %s: " + msg, set, String(Deno.pid), ...args);
};
} else {
debugImpls[set] = noop;
Expand Down
66 changes: 33 additions & 33 deletions tests/specs/node/node_debug/main.out
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
STREAM [WILDCARD] 'resume'
STREAM [WILDCARD] 'resume' false
STREAM [WILDCARD] 'read' 0
STREAM [WILDCARD] 'need readable' false
STREAM [WILDCARD] 'length less than watermark' true
STREAM [WILDCARD] 'reading, ended or constructing' false
STREAM [WILDCARD] 'flow' true
STREAM [WILDCARD] 'read' undefined
STREAM [WILDCARD] 'need readable' true
STREAM [WILDCARD] 'length less than watermark' true
STREAM [WILDCARD] 'reading, ended or constructing' false
STREAM [WILDCARD] 'read' 0
STREAM [WILDCARD] 'need readable' true
STREAM [WILDCARD] 'length less than watermark' true
STREAM [WILDCARD] 'reading, ended or constructing' false
STREAM [WILDCARD] 'maybeReadMore read 0'
STREAM [WILDCARD] 'read' 0
STREAM [WILDCARD] 'need readable' true
STREAM [WILDCARD] 'length less than watermark' true
STREAM [WILDCARD] 'do read'
STREAM [WILDCARD] 'readableAddChunk' <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a>
STREAM [WILDCARD]: resume
STREAM [WILDCARD]: resume false
STREAM [WILDCARD]: read 0
STREAM [WILDCARD]: need readable false
STREAM [WILDCARD]: length less than watermark true
STREAM [WILDCARD]: reading, ended or constructing false
STREAM [WILDCARD]: flow true
STREAM [WILDCARD]: read undefined
STREAM [WILDCARD]: need readable true
STREAM [WILDCARD]: length less than watermark true
STREAM [WILDCARD]: reading, ended or constructing false
STREAM [WILDCARD]: read 0
STREAM [WILDCARD]: need readable true
STREAM [WILDCARD]: length less than watermark true
STREAM [WILDCARD]: reading, ended or constructing false
STREAM [WILDCARD]: maybeReadMore read 0
STREAM [WILDCARD]: read 0
STREAM [WILDCARD]: need readable true
STREAM [WILDCARD]: length less than watermark true
STREAM [WILDCARD]: do read
STREAM [WILDCARD]: readableAddChunk <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a>
hello world

STREAM [WILDCARD] 'maybeReadMore read 0'
STREAM [WILDCARD] 'read' 0
STREAM [WILDCARD] 'need readable' true
STREAM [WILDCARD] 'length less than watermark' true
STREAM [WILDCARD] 'do read'
STREAM [WILDCARD] 'readableAddChunk' null
STREAM [WILDCARD] 'onEofChunk'
STREAM [WILDCARD] 'emitReadable_' false 0 true
STREAM [WILDCARD] 'flow' true
STREAM [WILDCARD] 'read' undefined
STREAM [WILDCARD] 'endReadable' false
STREAM [WILDCARD] 'endReadableNT' false 0
STREAM [WILDCARD]: maybeReadMore read 0
STREAM [WILDCARD]: read 0
STREAM [WILDCARD]: need readable true
STREAM [WILDCARD]: length less than watermark true
STREAM [WILDCARD]: do read
STREAM [WILDCARD]: readableAddChunk null
STREAM [WILDCARD]: onEofChunk
STREAM [WILDCARD]: emitReadable_ false 0 true
STREAM [WILDCARD]: flow true
STREAM [WILDCARD]: read undefined
STREAM [WILDCARD]: endReadable false
STREAM [WILDCARD]: endReadableNT false 0
Finished reading the file

0 comments on commit 773825a

Please sign in to comment.