@@ -32,6 +32,7 @@ const {
3232 ERR_INCOMPATIBLE_OPTION_PAIR ,
3333 } ,
3434} = require ( 'internal/errors' ) ;
35+ const { validateInteger } = require ( 'internal/validators' ) ;
3536const { previewEntries } = internalBinding ( 'util' ) ;
3637const { Buffer : { isBuffer } } = require ( 'buffer' ) ;
3738const {
@@ -52,12 +53,14 @@ const kTraceInstant = 'n'.charCodeAt(0);
5253const kSecond = 1000 ;
5354const kMinute = 60 * kSecond ;
5455const kHour = 60 * kMinute ;
56+ const kMaxGroupIndentation = 1000 ;
5557
5658// Lazy loaded for startup performance.
5759let cliTable ;
5860
5961// Track amount of indentation required via `console.group()`.
6062const kGroupIndent = Symbol ( 'kGroupIndent' ) ;
63+ const kGroupIndentationWidth = Symbol ( 'kGroupIndentWidth' ) ;
6164const kFormatForStderr = Symbol ( 'kFormatForStderr' ) ;
6265const kFormatForStdout = Symbol ( 'kFormatForStdout' ) ;
6366const kGetInspectOptions = Symbol ( 'kGetInspectOptions' ) ;
@@ -93,7 +96,8 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
9396 stderr = stdout ,
9497 ignoreErrors = true ,
9598 colorMode = 'auto' ,
96- inspectOptions
99+ inspectOptions,
100+ groupIndentation,
97101 } = options ;
98102
99103 if ( ! stdout || typeof stdout . write !== 'function' ) {
@@ -106,6 +110,11 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
106110 if ( typeof colorMode !== 'boolean' && colorMode !== 'auto' )
107111 throw new ERR_INVALID_ARG_VALUE ( 'colorMode' , colorMode ) ;
108112
113+ if ( groupIndentation !== undefined ) {
114+ validateInteger ( groupIndentation , 'groupIndentation' ,
115+ 0 , kMaxGroupIndentation ) ;
116+ }
117+
109118 if ( typeof inspectOptions === 'object' && inspectOptions !== null ) {
110119 if ( inspectOptions . colors !== undefined &&
111120 options . colorMode !== undefined ) {
@@ -130,7 +139,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
130139 }
131140
132141 this [ kBindStreamsEager ] ( stdout , stderr ) ;
133- this [ kBindProperties ] ( ignoreErrors , colorMode ) ;
142+ this [ kBindProperties ] ( ignoreErrors , colorMode , groupIndentation ) ;
134143}
135144
136145const consolePropAttributes = {
@@ -181,7 +190,8 @@ Console.prototype[kBindStreamsLazy] = function(object) {
181190 } ) ;
182191} ;
183192
184- Console . prototype [ kBindProperties ] = function ( ignoreErrors , colorMode ) {
193+ Console . prototype [ kBindProperties ] = function ( ignoreErrors , colorMode ,
194+ groupIndentation = 2 ) {
185195 ObjectDefineProperties ( this , {
186196 '_stdoutErrorHandler' : {
187197 ...consolePropAttributes ,
@@ -200,7 +210,11 @@ Console.prototype[kBindProperties] = function(ignoreErrors, colorMode) {
200210 [ kCounts ] : { ...consolePropAttributes , value : new Map ( ) } ,
201211 [ kColorMode ] : { ...consolePropAttributes , value : colorMode } ,
202212 [ kIsConsole ] : { ...consolePropAttributes , value : true } ,
203- [ kGroupIndent ] : { ...consolePropAttributes , value : '' }
213+ [ kGroupIndent ] : { ...consolePropAttributes , value : '' } ,
214+ [ kGroupIndentationWidth ] : {
215+ ...consolePropAttributes ,
216+ value : groupIndentation
217+ } ,
204218 } ) ;
205219} ;
206220
@@ -403,12 +417,13 @@ const consoleMethods = {
403417 if ( data . length > 0 ) {
404418 this . log ( ...data ) ;
405419 }
406- this [ kGroupIndent ] += ' ' ;
420+ this [ kGroupIndent ] += ' ' . repeat ( this [ kGroupIndentationWidth ] ) ;
407421 } ,
408422
409423 groupEnd ( ) {
410424 this [ kGroupIndent ] =
411- this [ kGroupIndent ] . slice ( 0 , this [ kGroupIndent ] . length - 2 ) ;
425+ this [ kGroupIndent ] . slice ( 0 , this [ kGroupIndent ] . length -
426+ this [ kGroupIndentationWidth ] ) ;
412427 } ,
413428
414429 // https://console.spec.whatwg.org/#table
0 commit comments