Skip to content

Commit 8869a4e

Browse files
authored
proper fix for #232699 (#233827)
* proper fix for #232699 * fix copy paste
1 parent a42d89c commit 8869a4e

File tree

4 files changed

+48
-40
lines changed

4 files changed

+48
-40
lines changed

src/vs/platform/log/common/log.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ export abstract class AbstractLogger extends Disposable implements ILogger {
259259
return this.level !== LogLevel.Off && this.level <= level;
260260
}
261261

262+
protected canLog(level: LogLevel): boolean {
263+
if (this._store.isDisposed) {
264+
return false;
265+
}
266+
return this.checkLogLevel(level);
267+
}
268+
262269
abstract trace(message: string, ...args: any[]): void;
263270
abstract debug(message: string, ...args: any[]): void;
264271
abstract info(message: string, ...args: any[]): void;
@@ -269,8 +276,6 @@ export abstract class AbstractLogger extends Disposable implements ILogger {
269276

270277
export abstract class AbstractMessageLogger extends AbstractLogger implements ILogger {
271278

272-
protected abstract log(level: LogLevel, message: string): void;
273-
274279
constructor(private readonly logAlways?: boolean) {
275280
super();
276281
}
@@ -280,32 +285,31 @@ export abstract class AbstractMessageLogger extends AbstractLogger implements IL
280285
}
281286

282287
trace(message: string, ...args: any[]): void {
283-
if (this.checkLogLevel(LogLevel.Trace)) {
288+
if (this.canLog(LogLevel.Trace)) {
284289
this.log(LogLevel.Trace, format([message, ...args], true));
285290
}
286291
}
287292

288293
debug(message: string, ...args: any[]): void {
289-
if (this.checkLogLevel(LogLevel.Debug)) {
294+
if (this.canLog(LogLevel.Debug)) {
290295
this.log(LogLevel.Debug, format([message, ...args]));
291296
}
292297
}
293298

294299
info(message: string, ...args: any[]): void {
295-
if (this.checkLogLevel(LogLevel.Info)) {
300+
if (this.canLog(LogLevel.Info)) {
296301
this.log(LogLevel.Info, format([message, ...args]));
297302
}
298303
}
299304

300305
warn(message: string, ...args: any[]): void {
301-
if (this.checkLogLevel(LogLevel.Warning)) {
306+
if (this.canLog(LogLevel.Warning)) {
302307
this.log(LogLevel.Warning, format([message, ...args]));
303308
}
304309
}
305310

306311
error(message: string | Error, ...args: any[]): void {
307-
if (this.checkLogLevel(LogLevel.Error)) {
308-
312+
if (this.canLog(LogLevel.Error)) {
309313
if (message instanceof Error) {
310314
const array = Array.prototype.slice.call(arguments) as any[];
311315
array[0] = message.stack;
@@ -317,6 +321,8 @@ export abstract class AbstractMessageLogger extends AbstractLogger implements IL
317321
}
318322

319323
flush(): void { }
324+
325+
protected abstract log(level: LogLevel, message: string): void;
320326
}
321327

322328

@@ -331,7 +337,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
331337
}
332338

333339
trace(message: string, ...args: any[]): void {
334-
if (this.checkLogLevel(LogLevel.Trace)) {
340+
if (this.canLog(LogLevel.Trace)) {
335341
if (this.useColors) {
336342
console.log(`\x1b[90m[main ${now()}]\x1b[0m`, message, ...args);
337343
} else {
@@ -341,7 +347,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
341347
}
342348

343349
debug(message: string, ...args: any[]): void {
344-
if (this.checkLogLevel(LogLevel.Debug)) {
350+
if (this.canLog(LogLevel.Debug)) {
345351
if (this.useColors) {
346352
console.log(`\x1b[90m[main ${now()}]\x1b[0m`, message, ...args);
347353
} else {
@@ -351,7 +357,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
351357
}
352358

353359
info(message: string, ...args: any[]): void {
354-
if (this.checkLogLevel(LogLevel.Info)) {
360+
if (this.canLog(LogLevel.Info)) {
355361
if (this.useColors) {
356362
console.log(`\x1b[90m[main ${now()}]\x1b[0m`, message, ...args);
357363
} else {
@@ -361,7 +367,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
361367
}
362368

363369
warn(message: string | Error, ...args: any[]): void {
364-
if (this.checkLogLevel(LogLevel.Warning)) {
370+
if (this.canLog(LogLevel.Warning)) {
365371
if (this.useColors) {
366372
console.warn(`\x1b[93m[main ${now()}]\x1b[0m`, message, ...args);
367373
} else {
@@ -371,7 +377,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
371377
}
372378

373379
error(message: string, ...args: any[]): void {
374-
if (this.checkLogLevel(LogLevel.Error)) {
380+
if (this.canLog(LogLevel.Error)) {
375381
if (this.useColors) {
376382
console.error(`\x1b[91m[main ${now()}]\x1b[0m`, message, ...args);
377383
} else {
@@ -394,7 +400,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
394400
}
395401

396402
trace(message: string, ...args: any[]): void {
397-
if (this.checkLogLevel(LogLevel.Trace)) {
403+
if (this.canLog(LogLevel.Trace)) {
398404
if (this.useColors) {
399405
console.log('%cTRACE', 'color: #888', message, ...args);
400406
} else {
@@ -404,7 +410,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
404410
}
405411

406412
debug(message: string, ...args: any[]): void {
407-
if (this.checkLogLevel(LogLevel.Debug)) {
413+
if (this.canLog(LogLevel.Debug)) {
408414
if (this.useColors) {
409415
console.log('%cDEBUG', 'background: #eee; color: #888', message, ...args);
410416
} else {
@@ -414,7 +420,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
414420
}
415421

416422
info(message: string, ...args: any[]): void {
417-
if (this.checkLogLevel(LogLevel.Info)) {
423+
if (this.canLog(LogLevel.Info)) {
418424
if (this.useColors) {
419425
console.log('%c INFO', 'color: #33f', message, ...args);
420426
} else {
@@ -424,7 +430,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
424430
}
425431

426432
warn(message: string | Error, ...args: any[]): void {
427-
if (this.checkLogLevel(LogLevel.Warning)) {
433+
if (this.canLog(LogLevel.Warning)) {
428434
if (this.useColors) {
429435
console.log('%c WARN', 'color: #993', message, ...args);
430436
} else {
@@ -434,7 +440,7 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
434440
}
435441

436442
error(message: string, ...args: any[]): void {
437-
if (this.checkLogLevel(LogLevel.Error)) {
443+
if (this.canLog(LogLevel.Error)) {
438444
if (this.useColors) {
439445
console.log('%c ERR', 'color: #f33', message, ...args);
440446
} else {
@@ -457,31 +463,31 @@ export class AdapterLogger extends AbstractLogger implements ILogger {
457463
}
458464

459465
trace(message: string, ...args: any[]): void {
460-
if (this.checkLogLevel(LogLevel.Trace)) {
466+
if (this.canLog(LogLevel.Trace)) {
461467
this.adapter.log(LogLevel.Trace, [this.extractMessage(message), ...args]);
462468
}
463469
}
464470

465471
debug(message: string, ...args: any[]): void {
466-
if (this.checkLogLevel(LogLevel.Debug)) {
472+
if (this.canLog(LogLevel.Debug)) {
467473
this.adapter.log(LogLevel.Debug, [this.extractMessage(message), ...args]);
468474
}
469475
}
470476

471477
info(message: string, ...args: any[]): void {
472-
if (this.checkLogLevel(LogLevel.Info)) {
478+
if (this.canLog(LogLevel.Info)) {
473479
this.adapter.log(LogLevel.Info, [this.extractMessage(message), ...args]);
474480
}
475481
}
476482

477483
warn(message: string | Error, ...args: any[]): void {
478-
if (this.checkLogLevel(LogLevel.Warning)) {
484+
if (this.canLog(LogLevel.Warning)) {
479485
this.adapter.log(LogLevel.Warning, [this.extractMessage(message), ...args]);
480486
}
481487
}
482488

483489
error(message: string | Error, ...args: any[]): void {
484-
if (this.checkLogLevel(LogLevel.Error)) {
490+
if (this.canLog(LogLevel.Error)) {
485491
this.adapter.log(LogLevel.Error, [this.extractMessage(message), ...args]);
486492
}
487493
}
@@ -491,7 +497,7 @@ export class AdapterLogger extends AbstractLogger implements ILogger {
491497
return msg;
492498
}
493499

494-
return toErrorMessage(msg, this.checkLogLevel(LogLevel.Trace));
500+
return toErrorMessage(msg, this.canLog(LogLevel.Trace));
495501
}
496502

497503
flush(): void {

src/vs/platform/log/node/spdlogLog.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,10 @@ export class SpdLogLogger extends AbstractMessageLogger implements ILogger {
110110
}
111111

112112
override flush(): void {
113-
if (this._store.isDisposed) {
114-
return;
115-
}
116-
117113
if (this._logger) {
118-
this._logger.flush();
114+
this.flushLogger();
119115
} else {
120-
this._loggerCreationPromise.then(() => this.flush());
116+
this._loggerCreationPromise.then(() => this.flushLogger());
121117
}
122118
}
123119

@@ -130,6 +126,12 @@ export class SpdLogLogger extends AbstractMessageLogger implements ILogger {
130126
super.dispose();
131127
}
132128

129+
private flushLogger(): void {
130+
if (this._logger) {
131+
this._logger.flush();
132+
}
133+
}
134+
133135
private disposeLogger(): void {
134136
if (this._logger) {
135137
this._logger.drop();

src/vs/platform/telemetry/test/common/telemetryLogAppender.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ class TestTelemetryLogger extends AbstractLogger implements ILogger {
2121
}
2222

2323
trace(message: string, ...args: any[]): void {
24-
if (this.checkLogLevel(LogLevel.Trace)) {
24+
if (this.canLog(LogLevel.Trace)) {
2525
this.logs.push(message + JSON.stringify(args));
2626
}
2727
}
2828

2929
debug(message: string, ...args: any[]): void {
30-
if (this.checkLogLevel(LogLevel.Debug)) {
30+
if (this.canLog(LogLevel.Debug)) {
3131
this.logs.push(message);
3232
}
3333
}
3434

3535
info(message: string, ...args: any[]): void {
36-
if (this.checkLogLevel(LogLevel.Info)) {
36+
if (this.canLog(LogLevel.Info)) {
3737
this.logs.push(message);
3838
}
3939
}
4040

4141
warn(message: string | Error, ...args: any[]): void {
42-
if (this.checkLogLevel(LogLevel.Warning)) {
42+
if (this.canLog(LogLevel.Warning)) {
4343
this.logs.push(message.toString());
4444
}
4545
}
4646

4747
error(message: string, ...args: any[]): void {
48-
if (this.checkLogLevel(LogLevel.Error)) {
48+
if (this.canLog(LogLevel.Error)) {
4949
this.logs.push(message);
5050
}
5151
}

src/vs/server/node/serverServices.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class ServerLogger extends AbstractLogger {
276276
}
277277

278278
trace(message: string, ...args: any[]): void {
279-
if (this.checkLogLevel(LogLevel.Trace)) {
279+
if (this.canLog(LogLevel.Trace)) {
280280
if (this.useColors) {
281281
console.log(`\x1b[90m[${now()}]\x1b[0m`, message, ...args);
282282
} else {
@@ -286,7 +286,7 @@ class ServerLogger extends AbstractLogger {
286286
}
287287

288288
debug(message: string, ...args: any[]): void {
289-
if (this.checkLogLevel(LogLevel.Debug)) {
289+
if (this.canLog(LogLevel.Debug)) {
290290
if (this.useColors) {
291291
console.log(`\x1b[90m[${now()}]\x1b[0m`, message, ...args);
292292
} else {
@@ -296,7 +296,7 @@ class ServerLogger extends AbstractLogger {
296296
}
297297

298298
info(message: string, ...args: any[]): void {
299-
if (this.checkLogLevel(LogLevel.Info)) {
299+
if (this.canLog(LogLevel.Info)) {
300300
if (this.useColors) {
301301
console.log(`\x1b[90m[${now()}]\x1b[0m`, message, ...args);
302302
} else {
@@ -306,7 +306,7 @@ class ServerLogger extends AbstractLogger {
306306
}
307307

308308
warn(message: string | Error, ...args: any[]): void {
309-
if (this.checkLogLevel(LogLevel.Warning)) {
309+
if (this.canLog(LogLevel.Warning)) {
310310
if (this.useColors) {
311311
console.warn(`\x1b[93m[${now()}]\x1b[0m`, message, ...args);
312312
} else {
@@ -316,7 +316,7 @@ class ServerLogger extends AbstractLogger {
316316
}
317317

318318
error(message: string, ...args: any[]): void {
319-
if (this.checkLogLevel(LogLevel.Error)) {
319+
if (this.canLog(LogLevel.Error)) {
320320
if (this.useColors) {
321321
console.error(`\x1b[91m[${now()}]\x1b[0m`, message, ...args);
322322
} else {

0 commit comments

Comments
 (0)