@@ -61,6 +61,8 @@ function Console(stdout, stderr, ignoreErrors = true) {
61
61
Object . defineProperty ( this , '_stderrErrorHandler' , prop ) ;
62
62
63
63
this [ kCounts ] = new Map ( ) ;
64
+
65
+ Object . defineProperty ( this , kGroupIndent , { writable : true } ) ;
64
66
this [ kGroupIndent ] = '' ;
65
67
66
68
// bind the prototype functions to this Console instance
@@ -87,7 +89,15 @@ function createWriteErrorHandler(stream) {
87
89
} ;
88
90
}
89
91
90
- function write ( ignoreErrors , stream , string , errorhandler ) {
92
+ function write ( ignoreErrors , stream , string , errorhandler , groupIndent ) {
93
+ if ( groupIndent . length !== 0 ) {
94
+ if ( string . indexOf ( '\n' ) !== - 1 ) {
95
+ string = string . replace ( / \n / g, `\n${ groupIndent } ` ) ;
96
+ }
97
+ string = groupIndent + string ;
98
+ }
99
+ string += '\n' ;
100
+
91
101
if ( ! ignoreErrors ) return stream . write ( string ) ;
92
102
93
103
// There may be an error occurring synchronously (e.g. for files or TTYs
@@ -116,8 +126,9 @@ function write(ignoreErrors, stream, string, errorhandler) {
116
126
Console . prototype . log = function log ( ...args ) {
117
127
write ( this . _ignoreErrors ,
118
128
this . _stdout ,
119
- `${ this [ kGroupIndent ] } ${ util . format . apply ( null , args ) } \n` ,
120
- this . _stdoutErrorHandler ) ;
129
+ util . format . apply ( null , args ) ,
130
+ this . _stdoutErrorHandler ,
131
+ this [ kGroupIndent ] ) ;
121
132
} ;
122
133
123
134
@@ -127,8 +138,9 @@ Console.prototype.info = Console.prototype.log;
127
138
Console . prototype . warn = function warn ( ...args ) {
128
139
write ( this . _ignoreErrors ,
129
140
this . _stderr ,
130
- `${ this [ kGroupIndent ] } ${ util . format . apply ( null , args ) } \n` ,
131
- this . _stderrErrorHandler ) ;
141
+ util . format . apply ( null , args ) ,
142
+ this . _stderrErrorHandler ,
143
+ this [ kGroupIndent ] ) ;
132
144
133
145
trace_mgr . emitTrace ( 'emitOnLogWarn' ) ; //ENABLE_TTD
134
146
} ;
@@ -147,8 +159,9 @@ Console.prototype.dir = function dir(object, options) {
147
159
options = Object . assign ( { customInspect : false } , options ) ;
148
160
write ( this . _ignoreErrors ,
149
161
this . _stdout ,
150
- `${ this [ kGroupIndent ] } ${ util . inspect ( object , options ) } \n` ,
151
- this . _stdoutErrorHandler ) ;
162
+ util . inspect ( object , options ) ,
163
+ this . _stdoutErrorHandler ,
164
+ this [ kGroupIndent ] ) ;
152
165
} ;
153
166
154
167
0 commit comments