@@ -61,6 +61,13 @@ const {
6161} = require ( 'internal/constants' ) ;
6262const kCounts = Symbol ( 'counts' ) ;
6363const { 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' ) ;
6471
6572const kTraceConsoleCategory = 'node,node.console' ;
6673
@@ -371,14 +378,39 @@ function timeLogImpl(consoleRef, label, formatted, args) {
371378
372379const consoleMethods = {
373380 log ( ...args ) {
381+ if ( onLog . hasSubscribers ) {
382+ onLog . publish ( args ) ;
383+ }
374384 this [ kWriteToConsole ] ( kUseStdout , this [ kFormatForStdout ] ( args ) ) ;
375385 } ,
376386
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+ } ,
377400
378401 warn ( ...args ) {
402+ if ( onWarn . hasSubscribers ) {
403+ onWarn . publish ( args ) ;
404+ }
379405 this [ kWriteToConsole ] ( kUseStderr , this [ kFormatForStderr ] ( args ) ) ;
380406 } ,
381407
408+ error ( ...args ) {
409+ if ( onError . hasSubscribers ) {
410+ onError . publish ( args ) ;
411+ }
412+ this [ kWriteToConsole ] ( kUseStderr , this [ kFormatForStderr ] ( args ) ) ;
413+ } ,
382414
383415 dir ( object , options ) {
384416 this [ kWriteToConsole ] ( kUseStdout , inspect ( object , {
@@ -614,10 +646,7 @@ function noop() {}
614646for ( const method of ReflectOwnKeys ( consoleMethods ) )
615647 Console . prototype [ method ] = consoleMethods [ method ] ;
616648
617- Console . prototype . debug = Console . prototype . log ;
618- Console . prototype . info = Console . prototype . log ;
619649Console . prototype . dirxml = Console . prototype . log ;
620- Console . prototype . error = Console . prototype . warn ;
621650Console . prototype . groupCollapsed = Console . prototype . group ;
622651
623652function initializeGlobalConsole ( globalConsole ) {
0 commit comments