@@ -259,6 +259,13 @@ export abstract class AbstractLogger extends Disposable implements ILogger {
259
259
return this . level !== LogLevel . Off && this . level <= level ;
260
260
}
261
261
262
+ protected canLog ( level : LogLevel ) : boolean {
263
+ if ( this . _store . isDisposed ) {
264
+ return false ;
265
+ }
266
+ return this . checkLogLevel ( level ) ;
267
+ }
268
+
262
269
abstract trace ( message : string , ...args : any [ ] ) : void ;
263
270
abstract debug ( message : string , ...args : any [ ] ) : void ;
264
271
abstract info ( message : string , ...args : any [ ] ) : void ;
@@ -269,8 +276,6 @@ export abstract class AbstractLogger extends Disposable implements ILogger {
269
276
270
277
export abstract class AbstractMessageLogger extends AbstractLogger implements ILogger {
271
278
272
- protected abstract log ( level : LogLevel , message : string ) : void ;
273
-
274
279
constructor ( private readonly logAlways ?: boolean ) {
275
280
super ( ) ;
276
281
}
@@ -280,32 +285,31 @@ export abstract class AbstractMessageLogger extends AbstractLogger implements IL
280
285
}
281
286
282
287
trace ( message : string , ...args : any [ ] ) : void {
283
- if ( this . checkLogLevel ( LogLevel . Trace ) ) {
288
+ if ( this . canLog ( LogLevel . Trace ) ) {
284
289
this . log ( LogLevel . Trace , format ( [ message , ...args ] , true ) ) ;
285
290
}
286
291
}
287
292
288
293
debug ( message : string , ...args : any [ ] ) : void {
289
- if ( this . checkLogLevel ( LogLevel . Debug ) ) {
294
+ if ( this . canLog ( LogLevel . Debug ) ) {
290
295
this . log ( LogLevel . Debug , format ( [ message , ...args ] ) ) ;
291
296
}
292
297
}
293
298
294
299
info ( message : string , ...args : any [ ] ) : void {
295
- if ( this . checkLogLevel ( LogLevel . Info ) ) {
300
+ if ( this . canLog ( LogLevel . Info ) ) {
296
301
this . log ( LogLevel . Info , format ( [ message , ...args ] ) ) ;
297
302
}
298
303
}
299
304
300
305
warn ( message : string , ...args : any [ ] ) : void {
301
- if ( this . checkLogLevel ( LogLevel . Warning ) ) {
306
+ if ( this . canLog ( LogLevel . Warning ) ) {
302
307
this . log ( LogLevel . Warning , format ( [ message , ...args ] ) ) ;
303
308
}
304
309
}
305
310
306
311
error ( message : string | Error , ...args : any [ ] ) : void {
307
- if ( this . checkLogLevel ( LogLevel . Error ) ) {
308
-
312
+ if ( this . canLog ( LogLevel . Error ) ) {
309
313
if ( message instanceof Error ) {
310
314
const array = Array . prototype . slice . call ( arguments ) as any [ ] ;
311
315
array [ 0 ] = message . stack ;
@@ -317,6 +321,8 @@ export abstract class AbstractMessageLogger extends AbstractLogger implements IL
317
321
}
318
322
319
323
flush ( ) : void { }
324
+
325
+ protected abstract log ( level : LogLevel , message : string ) : void ;
320
326
}
321
327
322
328
@@ -331,7 +337,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
331
337
}
332
338
333
339
trace ( message : string , ...args : any [ ] ) : void {
334
- if ( this . checkLogLevel ( LogLevel . Trace ) ) {
340
+ if ( this . canLog ( LogLevel . Trace ) ) {
335
341
if ( this . useColors ) {
336
342
console . log ( `\x1b[90m[main ${ now ( ) } ]\x1b[0m` , message , ...args ) ;
337
343
} else {
@@ -341,7 +347,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
341
347
}
342
348
343
349
debug ( message : string , ...args : any [ ] ) : void {
344
- if ( this . checkLogLevel ( LogLevel . Debug ) ) {
350
+ if ( this . canLog ( LogLevel . Debug ) ) {
345
351
if ( this . useColors ) {
346
352
console . log ( `\x1b[90m[main ${ now ( ) } ]\x1b[0m` , message , ...args ) ;
347
353
} else {
@@ -351,7 +357,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
351
357
}
352
358
353
359
info ( message : string , ...args : any [ ] ) : void {
354
- if ( this . checkLogLevel ( LogLevel . Info ) ) {
360
+ if ( this . canLog ( LogLevel . Info ) ) {
355
361
if ( this . useColors ) {
356
362
console . log ( `\x1b[90m[main ${ now ( ) } ]\x1b[0m` , message , ...args ) ;
357
363
} else {
@@ -361,7 +367,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
361
367
}
362
368
363
369
warn ( message : string | Error , ...args : any [ ] ) : void {
364
- if ( this . checkLogLevel ( LogLevel . Warning ) ) {
370
+ if ( this . canLog ( LogLevel . Warning ) ) {
365
371
if ( this . useColors ) {
366
372
console . warn ( `\x1b[93m[main ${ now ( ) } ]\x1b[0m` , message , ...args ) ;
367
373
} else {
@@ -371,7 +377,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
371
377
}
372
378
373
379
error ( message : string , ...args : any [ ] ) : void {
374
- if ( this . checkLogLevel ( LogLevel . Error ) ) {
380
+ if ( this . canLog ( LogLevel . Error ) ) {
375
381
if ( this . useColors ) {
376
382
console . error ( `\x1b[91m[main ${ now ( ) } ]\x1b[0m` , message , ...args ) ;
377
383
} else {
@@ -394,7 +400,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
394
400
}
395
401
396
402
trace ( message : string , ...args : any [ ] ) : void {
397
- if ( this . checkLogLevel ( LogLevel . Trace ) ) {
403
+ if ( this . canLog ( LogLevel . Trace ) ) {
398
404
if ( this . useColors ) {
399
405
console . log ( '%cTRACE' , 'color: #888' , message , ...args ) ;
400
406
} else {
@@ -404,7 +410,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
404
410
}
405
411
406
412
debug ( message : string , ...args : any [ ] ) : void {
407
- if ( this . checkLogLevel ( LogLevel . Debug ) ) {
413
+ if ( this . canLog ( LogLevel . Debug ) ) {
408
414
if ( this . useColors ) {
409
415
console . log ( '%cDEBUG' , 'background: #eee; color: #888' , message , ...args ) ;
410
416
} else {
@@ -414,7 +420,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
414
420
}
415
421
416
422
info ( message : string , ...args : any [ ] ) : void {
417
- if ( this . checkLogLevel ( LogLevel . Info ) ) {
423
+ if ( this . canLog ( LogLevel . Info ) ) {
418
424
if ( this . useColors ) {
419
425
console . log ( '%c INFO' , 'color: #33f' , message , ...args ) ;
420
426
} else {
@@ -424,7 +430,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
424
430
}
425
431
426
432
warn ( message : string | Error , ...args : any [ ] ) : void {
427
- if ( this . checkLogLevel ( LogLevel . Warning ) ) {
433
+ if ( this . canLog ( LogLevel . Warning ) ) {
428
434
if ( this . useColors ) {
429
435
console . log ( '%c WARN' , 'color: #993' , message , ...args ) ;
430
436
} else {
@@ -434,7 +440,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
434
440
}
435
441
436
442
error ( message : string , ...args : any [ ] ) : void {
437
- if ( this . checkLogLevel ( LogLevel . Error ) ) {
443
+ if ( this . canLog ( LogLevel . Error ) ) {
438
444
if ( this . useColors ) {
439
445
console . log ( '%c ERR' , 'color: #f33' , message , ...args ) ;
440
446
} else {
@@ -457,31 +463,31 @@ export class AdapterLogger extends AbstractLogger implements ILogger {
457
463
}
458
464
459
465
trace ( message : string , ...args : any [ ] ) : void {
460
- if ( this . checkLogLevel ( LogLevel . Trace ) ) {
466
+ if ( this . canLog ( LogLevel . Trace ) ) {
461
467
this . adapter . log ( LogLevel . Trace , [ this . extractMessage ( message ) , ...args ] ) ;
462
468
}
463
469
}
464
470
465
471
debug ( message : string , ...args : any [ ] ) : void {
466
- if ( this . checkLogLevel ( LogLevel . Debug ) ) {
472
+ if ( this . canLog ( LogLevel . Debug ) ) {
467
473
this . adapter . log ( LogLevel . Debug , [ this . extractMessage ( message ) , ...args ] ) ;
468
474
}
469
475
}
470
476
471
477
info ( message : string , ...args : any [ ] ) : void {
472
- if ( this . checkLogLevel ( LogLevel . Info ) ) {
478
+ if ( this . canLog ( LogLevel . Info ) ) {
473
479
this . adapter . log ( LogLevel . Info , [ this . extractMessage ( message ) , ...args ] ) ;
474
480
}
475
481
}
476
482
477
483
warn ( message : string | Error , ...args : any [ ] ) : void {
478
- if ( this . checkLogLevel ( LogLevel . Warning ) ) {
484
+ if ( this . canLog ( LogLevel . Warning ) ) {
479
485
this . adapter . log ( LogLevel . Warning , [ this . extractMessage ( message ) , ...args ] ) ;
480
486
}
481
487
}
482
488
483
489
error ( message : string | Error , ...args : any [ ] ) : void {
484
- if ( this . checkLogLevel ( LogLevel . Error ) ) {
490
+ if ( this . canLog ( LogLevel . Error ) ) {
485
491
this . adapter . log ( LogLevel . Error , [ this . extractMessage ( message ) , ...args ] ) ;
486
492
}
487
493
}
@@ -491,7 +497,7 @@ export class AdapterLogger extends AbstractLogger implements ILogger {
491
497
return msg ;
492
498
}
493
499
494
- return toErrorMessage ( msg , this . checkLogLevel ( LogLevel . Trace ) ) ;
500
+ return toErrorMessage ( msg , this . canLog ( LogLevel . Trace ) ) ;
495
501
}
496
502
497
503
flush ( ) : void {
0 commit comments