@@ -139,8 +139,6 @@ namespace ts.server {
139139 class Logger implements server . Logger {
140140 private fd = - 1 ;
141141 private seq = 0 ;
142- private inGroup = false ;
143- private firstInGroup = true ;
144142
145143 constructor ( private readonly logFilename : string ,
146144 private readonly traceToConsole : boolean ,
@@ -170,22 +168,24 @@ namespace ts.server {
170168 }
171169
172170 perftrc ( s : string ) {
173- this . msg ( s , Msg . Perf ) ;
171+ this . msg ( s , " Perf" ) ;
174172 }
175173
176174 info ( s : string ) {
177- this . msg ( s , Msg . Info ) ;
175+ this . msg ( s , " Info" ) ;
178176 }
179177
180- startGroup ( ) {
181- this . inGroup = true ;
182- this . firstInGroup = true ;
178+ err ( s : string ) {
179+ this . msg ( s , "Err" ) ;
183180 }
184181
185- endGroup ( ) {
186- this . inGroup = false ;
182+ group ( logGroupEntries : ( log : ( msg : string ) => void ) => void ) {
183+ let firstInGroup = false ;
184+ logGroupEntries ( s => {
185+ this . msg ( s , "Info" , /*inGroup*/ true , firstInGroup ) ;
186+ firstInGroup = false ;
187+ } ) ;
187188 this . seq ++ ;
188- this . firstInGroup = true ;
189189 }
190190
191191 loggingEnabled ( ) {
@@ -196,26 +196,32 @@ namespace ts.server {
196196 return this . loggingEnabled ( ) && this . level >= level ;
197197 }
198198
199- msg ( s : string , type : Msg . Types = Msg . Err ) {
200- if ( this . fd >= 0 || this . traceToConsole ) {
201- s = `[${ nowString ( ) } ] ${ s } \n` ;
199+ private msg ( s : string , type : string , inGroup = false , firstInGroup = false ) {
200+ if ( ! this . canWrite ) return ;
201+
202+ s = `[${ nowString ( ) } ] ${ s } \n` ;
203+ if ( ! inGroup || firstInGroup ) {
202204 const prefix = Logger . padStringRight ( type + " " + this . seq . toString ( ) , " " ) ;
203- if ( this . firstInGroup ) {
204- s = prefix + s ;
205- this . firstInGroup = false ;
206- }
207- if ( ! this . inGroup ) {
208- this . seq ++ ;
209- this . firstInGroup = true ;
210- }
211- if ( this . fd >= 0 ) {
212- const buf = new Buffer ( s ) ;
213- // tslint:disable-next-line no-null-keyword
214- fs . writeSync ( this . fd , buf , 0 , buf . length , /*position*/ null ) ;
215- }
216- if ( this . traceToConsole ) {
217- console . warn ( s ) ;
218- }
205+ s = prefix + s ;
206+ }
207+ this . write ( s ) ;
208+ if ( ! inGroup ) {
209+ this . seq ++ ;
210+ }
211+ }
212+
213+ private get canWrite ( ) {
214+ return this . fd >= 0 || this . traceToConsole ;
215+ }
216+
217+ private write ( s : string ) {
218+ if ( this . fd >= 0 ) {
219+ const buf = new Buffer ( s ) ;
220+ // tslint:disable-next-line no-null-keyword
221+ fs . writeSync ( this . fd , buf , 0 , buf . length , /*position*/ null ) ;
222+ }
223+ if ( this . traceToConsole ) {
224+ console . warn ( s ) ;
219225 }
220226 }
221227 }
0 commit comments