| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2042628 commit 28bec2d
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1120,6 +1120,43 @@ While the diagnostics\_channel API is now considered stable, the built-in | |||
| 1120 | 1120 | channels currently available are not. Each channel must be declared stable | |
| 1121 | 1121 | independently. | |
| 1122 | 1122 | ||
| 1123 | + #### Console | ||
| 1124 | + | ||
| 1125 | + `console.log` | ||
| 1126 | + | ||
| 1127 | + * `args` {any\[]} | ||
| 1128 | + | ||
| 1129 | + Emitted when `console.log()` is called. Receives and array of the arguments | ||
| 1130 | + passed to `console.log()`. | ||
| 1131 | + | ||
| 1132 | + `console.info` | ||
| 1133 | + | ||
| 1134 | + * `args` {any\[]} | ||
| 1135 | + | ||
| 1136 | + Emitted when `console.info()` is called. Receives and array of the arguments | ||
| 1137 | + passed to `console.info()`. | ||
| 1138 | + | ||
| 1139 | + `console.debug` | ||
| 1140 | + | ||
| 1141 | + * `args` {any\[]} | ||
| 1142 | + | ||
| 1143 | + Emitted when `console.debug()` is called. Receives and array of the arguments | ||
| 1144 | + passed to `console.debug()`. | ||
| 1145 | + | ||
| 1146 | + `console.warn` | ||
| 1147 | + | ||
| 1148 | + * `args` {any\[]} | ||
| 1149 | + | ||
| 1150 | + Emitted when `console.warn()` is called. Receives and array of the arguments | ||
| 1151 | + passed to `console.warn()`. | ||
| 1152 | + | ||
| 1153 | + `console.error` | ||
| 1154 | + | ||
| 1155 | + * `args` {any\[]} | ||
| 1156 | + | ||
| 1157 | + Emitted when `console.error()` is called. Receives and array of the arguments | ||
| 1158 | + passed to `console.error()`. | ||
| 1159 | + | ||
| 1123 | 1160 | #### HTTP | |
| 1124 | 1161 | ||
| 1125 | 1162 | `http.client.request.created` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,6 +61,13 @@ const { | |||
| 61 | 61 | } = require('internal/constants'); | |
| 62 | 62 | const kCounts = Symbol('counts'); | |
| 63 | 63 | const { time, timeLog, timeEnd, kNone } = require('internal/util/debuglog'); | |
| 64 | + const { channel } = require('diagnostics_channel'); | ||
| 65 | + | ||
| 66 | + const onLog = channel('console.log'); | ||
| 67 | + const onWarn = channel('console.warn'); | ||
| 68 | + const onError = channel('console.error'); | ||
| 69 | + const onInfo = channel('console.info'); | ||
| 70 | + const onDebug = channel('console.debug'); | ||
| 64 | 71 | ||
| 65 | 72 | const kTraceConsoleCategory = 'node,node.console'; | |
| 66 | 73 | ||
@@ -371,14 +378,39 @@ function timeLogImpl(consoleRef, label, formatted, args) { | |||
| 371 | 378 | ||
| 372 | 379 | const consoleMethods = { | |
| 373 | 380 | log(...args) { | |
| 381 | + if (onLog.hasSubscribers) { | ||
| 382 | + onLog.publish(args); | ||
| 383 | + } | ||
| 374 | 384 | this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args)); | |
| 375 | 385 | }, | |
| 376 | 386 | ||
| 387 | + info(...args) { | ||
| 388 | + if (onInfo.hasSubscribers) { | ||
| 389 | + onInfo.publish(args); | ||
| 390 | + } | ||
| 391 | + this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args)); | ||
| 392 | + }, | ||
| 393 | + | ||
| 394 | + debug(...args) { | ||
| 395 | + if (onDebug.hasSubscribers) { | ||
| 396 | + onDebug.publish(args); | ||
| 397 | + } | ||
| 398 | + this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args)); | ||
| 399 | + }, | ||
| 377 | 400 | ||
| 378 | 401 | warn(...args) { | |
| 402 | + if (onWarn.hasSubscribers) { | ||
| 403 | + onWarn.publish(args); | ||
| 404 | + } | ||
| 379 | 405 | this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args)); | |
| 380 | 406 | }, | |
| 381 | 407 | ||
| 408 | + error(...args) { | ||
| 409 | + if (onError.hasSubscribers) { | ||
| 410 | + onError.publish(args); | ||
| 411 | + } | ||
| 412 | + this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args)); | ||
| 413 | + }, | ||
| 382 | 414 | ||
| 383 | 415 | dir(object, options) { | |
| 384 | 416 | this[kWriteToConsole](kUseStdout, inspect(object, { | |
@@ -614,10 +646,7 @@ function noop() {} | |||
| 614 | 646 | for (const method of ReflectOwnKeys(consoleMethods)) | |
| 615 | 647 | Console.prototype[method] = consoleMethods[method]; | |
| 616 | 648 | ||
| 617 | - Console.prototype.debug = Console.prototype.log; | ||
| 618 | - Console.prototype.info = Console.prototype.log; | ||
| 619 | 649 | Console.prototype.dirxml = Console.prototype.log; | |
| 620 | - Console.prototype.error = Console.prototype.warn; | ||
| 621 | 650 | Console.prototype.groupCollapsed = Console.prototype.group; | |
| 622 | 651 | ||
| 623 | 652 | function initializeGlobalConsole(globalConsole) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,77 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { mustCall } = require('../common'); | ||
| 4 | + const { deepStrictEqual, ok, strictEqual } = require('assert'); | ||
| 5 | + | ||
| 6 | + const { channel } = require('diagnostics_channel'); | ||
| 7 | + | ||
| 8 | + const { | ||
| 9 | + hijackStdout, | ||
| 10 | + hijackStderr, | ||
| 11 | + restoreStdout, | ||
| 12 | + restoreStderr | ||
| 13 | + } = require('../common/hijackstdio'); | ||
| 14 | + | ||
| 15 | + const stdoutMethods = [ | ||
| 16 | + 'log', | ||
| 17 | + 'info', | ||
| 18 | + 'debug', | ||
| 19 | + ]; | ||
| 20 | + | ||
| 21 | + const stderrMethods = [ | ||
| 22 | + 'warn', | ||
| 23 | + 'error', | ||
| 24 | + ]; | ||
| 25 | + | ||
| 26 | + const methods = [ | ||
| 27 | + ...stdoutMethods, | ||
| 28 | + ...stderrMethods, | ||
| 29 | + ]; | ||
| 30 | + | ||
| 31 | + const channels = { | ||
| 32 | + log: channel('console.log'), | ||
| 33 | + info: channel('console.info'), | ||
| 34 | + debug: channel('console.debug'), | ||
| 35 | + warn: channel('console.warn'), | ||
| 36 | + error: channel('console.error') | ||
| 37 | + }; | ||
| 38 | + | ||
| 39 | + process.stdout.isTTY = false; | ||
| 40 | + process.stderr.isTTY = false; | ||
| 41 | + | ||
| 42 | + for (const method of methods) { | ||
| 43 | + let intercepted = false; | ||
| 44 | + let formatted = false; | ||
| 45 | + | ||
| 46 | + const isStdout = stdoutMethods.includes(method); | ||
| 47 | + const hijack = isStdout ? hijackStdout : hijackStderr; | ||
| 48 | + const restore = isStdout ? restoreStdout : restoreStderr; | ||
| 49 | + | ||
| 50 | + const foo = 'string'; | ||
| 51 | + const bar = { key: /value/ }; | ||
| 52 | + const baz = [ 1, 2, 3 ]; | ||
| 53 | + | ||
| 54 | + channels[method].subscribe(mustCall((args) => { | ||
| 55 | + // Should not have been formatted yet. | ||
| 56 | + intercepted = true; | ||
| 57 | + ok(!formatted); | ||
| 58 | + | ||
| 59 | + // Should receive expected log message args. | ||
| 60 | + deepStrictEqual(args, [foo, bar, baz]); | ||
| 61 | + | ||
| 62 | + // Should be able to mutate message args and have it reflected in output. | ||
| 63 | + bar.added = true; | ||
| 64 | + })); | ||
| 65 | + | ||
| 66 | + hijack(mustCall((output) => { | ||
| 67 | + // Should have already been intercepted. | ||
| 68 | + formatted = true; | ||
| 69 | + ok(intercepted); | ||
| 70 | + | ||
| 71 | + // Should produce expected formatted output with mutated message args. | ||
| 72 | + strictEqual(output, 'string { key: /value/, added: true } [ 1, 2, 3 ]\n'); | ||
| 73 | + })); | ||
| 74 | + | ||
| 75 | + console[method](foo, bar, baz); | ||
| 76 | + restore(); | ||
| 77 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -792,7 +792,10 @@ const errorTests = [ | |||
| 792 | 792 | expect: [ | |
| 793 | 793 | 'Object [console] {', | |
| 794 | 794 | ' log: [Function: log],', | |
| 795 | + ' info: [Function: info],', | ||
| 796 | + ' debug: [Function: debug],', | ||
| 795 | 797 | ' warn: [Function: warn],', | |
| 798 | + ' error: [Function: error],', | ||
| 796 | 799 | ' dir: [Function: dir],', | |
| 797 | 800 | ' time: [Function: time],', | |
| 798 | 801 | ' timeEnd: [Function: timeEnd],', | |
@@ -805,10 +808,7 @@ const errorTests = [ | |||
| 805 | 808 | ' group: [Function: group],', | |
| 806 | 809 | ' groupEnd: [Function: groupEnd],', | |
| 807 | 810 | ' table: [Function: table],', | |
| 808 | - / {2}debug: \[Function: (debug|log)],/, | ||
| 809 | - / {2}info: \[Function: (info|log)],/, | ||
| 810 | 811 | / {2}dirxml: \[Function: (dirxml|log)],/, | |
| 811 | - / {2}error: \[Function: (error|warn)],/, | ||
| 812 | 812 | / {2}groupCollapsed: \[Function: (groupCollapsed|group)],/, | |
| 813 | 813 | / {2}Console: \[Function: Console],?/, | |
| 814 | 814 | ...process.features.inspector ? [ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments