Skip to content

Commit d0e44be

Browse files
authored
1 parent 2fc0421 commit d0e44be

File tree

6 files changed

+40
-74
lines changed

6 files changed

+40
-74
lines changed

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

+4-42
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { basename, dirname, joinPath } from 'vs/base/common/resources';
99
import { URI } from 'vs/base/common/uri';
1010
import { ByteSize, FileOperationError, FileOperationResult, IFileService, whenProviderRegistered } from 'vs/platform/files/common/files';
1111
import { BufferLogService } from 'vs/platform/log/common/bufferLog';
12-
import { AbstractLogger, AbstractLoggerService, format, ILogger, ILoggerOptions, ILoggerService, ILogService, LogLevel } from 'vs/platform/log/common/log';
12+
import { AbstractLoggerService, AbstractMessageLogger, ILogger, ILoggerOptions, ILoggerService, ILogService, LogLevel } from 'vs/platform/log/common/log';
1313

1414
const MAX_FILE_SIZE = 5 * ByteSize.MB;
1515

16-
export class FileLogger extends AbstractLogger implements ILogger {
16+
export class FileLogger extends AbstractMessageLogger implements ILogger {
1717

1818
private readonly initializePromise: Promise<void>;
1919
private readonly queue: Queue<void>;
@@ -32,45 +32,7 @@ export class FileLogger extends AbstractLogger implements ILogger {
3232
this.initializePromise = this.initialize();
3333
}
3434

35-
trace(): void {
36-
if (this.getLevel() <= LogLevel.Trace) {
37-
this._log(LogLevel.Trace, format(arguments));
38-
}
39-
}
40-
41-
debug(): void {
42-
if (this.getLevel() <= LogLevel.Debug) {
43-
this._log(LogLevel.Debug, format(arguments));
44-
}
45-
}
46-
47-
info(): void {
48-
if (this.getLevel() <= LogLevel.Info) {
49-
this._log(LogLevel.Info, format(arguments));
50-
}
51-
}
52-
53-
warn(): void {
54-
if (this.getLevel() <= LogLevel.Warning) {
55-
this._log(LogLevel.Warning, format(arguments));
56-
}
57-
}
58-
59-
error(): void {
60-
if (this.getLevel() <= LogLevel.Error) {
61-
const arg = arguments[0];
62-
63-
if (arg instanceof Error) {
64-
const array = Array.prototype.slice.call(arguments) as any[];
65-
array[0] = arg.stack;
66-
this._log(LogLevel.Error, format(array));
67-
} else {
68-
this._log(LogLevel.Error, format(arguments));
69-
}
70-
}
71-
}
72-
73-
flush(): void {
35+
override flush(): void {
7436
}
7537

7638
private async initialize(): Promise<void> {
@@ -83,7 +45,7 @@ export class FileLogger extends AbstractLogger implements ILogger {
8345
}
8446
}
8547

86-
private _log(level: LogLevel, message: string): void {
48+
protected log(level: LogLevel, message: string): void {
8749
this.queue.queue(async () => {
8850
await this.initializePromise;
8951
let content = await this.loadContent();

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

+23-18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function log(logger: ILogger, level: LogLevel, message: string): void {
5454
case LogLevel.Info: logger.info(message); break;
5555
case LogLevel.Warning: logger.warn(message); break;
5656
case LogLevel.Error: logger.error(message); break;
57+
case LogLevel.Off: /* do nothing */ break;
5758
default: throw new Error(`Invalid log level ${level}`);
5859
}
5960
}
@@ -144,6 +145,10 @@ export abstract class AbstractLogger extends Disposable {
144145
return this.level;
145146
}
146147

148+
protected checkLogLevel(level: LogLevel): boolean {
149+
return this.level !== LogLevel.Off && this.level <= level;
150+
}
151+
147152
}
148153

149154
export abstract class AbstractMessageLogger extends AbstractLogger implements ILogger {
@@ -154,8 +159,8 @@ export abstract class AbstractMessageLogger extends AbstractLogger implements IL
154159
super();
155160
}
156161

157-
private checkLogLevel(level: LogLevel): boolean {
158-
return this.logAlways || this.getLevel() <= level;
162+
protected override checkLogLevel(level: LogLevel): boolean {
163+
return this.logAlways || super.checkLogLevel(level);
159164
}
160165

161166
trace(message: string, ...args: any[]): void {
@@ -210,7 +215,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
210215
}
211216

212217
trace(message: string, ...args: any[]): void {
213-
if (this.getLevel() <= LogLevel.Trace) {
218+
if (this.checkLogLevel(LogLevel.Trace)) {
214219
if (this.useColors) {
215220
console.log(`\x1b[90m[main ${now()}]\x1b[0m`, message, ...args);
216221
} else {
@@ -220,7 +225,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
220225
}
221226

222227
debug(message: string, ...args: any[]): void {
223-
if (this.getLevel() <= LogLevel.Debug) {
228+
if (this.checkLogLevel(LogLevel.Debug)) {
224229
if (this.useColors) {
225230
console.log(`\x1b[90m[main ${now()}]\x1b[0m`, message, ...args);
226231
} else {
@@ -230,7 +235,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
230235
}
231236

232237
info(message: string, ...args: any[]): void {
233-
if (this.getLevel() <= LogLevel.Info) {
238+
if (this.checkLogLevel(LogLevel.Info)) {
234239
if (this.useColors) {
235240
console.log(`\x1b[90m[main ${now()}]\x1b[0m`, message, ...args);
236241
} else {
@@ -240,7 +245,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
240245
}
241246

242247
warn(message: string | Error, ...args: any[]): void {
243-
if (this.getLevel() <= LogLevel.Warning) {
248+
if (this.checkLogLevel(LogLevel.Warning)) {
244249
if (this.useColors) {
245250
console.warn(`\x1b[93m[main ${now()}]\x1b[0m`, message, ...args);
246251
} else {
@@ -250,7 +255,7 @@ export class ConsoleMainLogger extends AbstractLogger implements ILogger {
250255
}
251256

252257
error(message: string, ...args: any[]): void {
253-
if (this.getLevel() <= LogLevel.Error) {
258+
if (this.checkLogLevel(LogLevel.Error)) {
254259
if (this.useColors) {
255260
console.error(`\x1b[91m[main ${now()}]\x1b[0m`, message, ...args);
256261
} else {
@@ -277,31 +282,31 @@ export class ConsoleLogger extends AbstractLogger implements ILogger {
277282
}
278283

279284
trace(message: string, ...args: any[]): void {
280-
if (this.getLevel() <= LogLevel.Trace) {
285+
if (this.checkLogLevel(LogLevel.Trace)) {
281286
console.log('%cTRACE', 'color: #888', message, ...args);
282287
}
283288
}
284289

285290
debug(message: string, ...args: any[]): void {
286-
if (this.getLevel() <= LogLevel.Debug) {
291+
if (this.checkLogLevel(LogLevel.Debug)) {
287292
console.log('%cDEBUG', 'background: #eee; color: #888', message, ...args);
288293
}
289294
}
290295

291296
info(message: string, ...args: any[]): void {
292-
if (this.getLevel() <= LogLevel.Info) {
297+
if (this.checkLogLevel(LogLevel.Info)) {
293298
console.log('%c INFO', 'color: #33f', message, ...args);
294299
}
295300
}
296301

297302
warn(message: string | Error, ...args: any[]): void {
298-
if (this.getLevel() <= LogLevel.Warning) {
303+
if (this.checkLogLevel(LogLevel.Warning)) {
299304
console.log('%c WARN', 'color: #993', message, ...args);
300305
}
301306
}
302307

303308
error(message: string, ...args: any[]): void {
304-
if (this.getLevel() <= LogLevel.Error) {
309+
if (this.checkLogLevel(LogLevel.Error)) {
305310
console.log('%c ERR', 'color: #f33', message, ...args);
306311
}
307312
}
@@ -323,31 +328,31 @@ export class AdapterLogger extends AbstractLogger implements ILogger {
323328
}
324329

325330
trace(message: string, ...args: any[]): void {
326-
if (this.getLevel() <= LogLevel.Trace) {
331+
if (this.checkLogLevel(LogLevel.Trace)) {
327332
this.adapter.log(LogLevel.Trace, [this.extractMessage(message), ...args]);
328333
}
329334
}
330335

331336
debug(message: string, ...args: any[]): void {
332-
if (this.getLevel() <= LogLevel.Debug) {
337+
if (this.checkLogLevel(LogLevel.Debug)) {
333338
this.adapter.log(LogLevel.Debug, [this.extractMessage(message), ...args]);
334339
}
335340
}
336341

337342
info(message: string, ...args: any[]): void {
338-
if (this.getLevel() <= LogLevel.Info) {
343+
if (this.checkLogLevel(LogLevel.Info)) {
339344
this.adapter.log(LogLevel.Info, [this.extractMessage(message), ...args]);
340345
}
341346
}
342347

343348
warn(message: string | Error, ...args: any[]): void {
344-
if (this.getLevel() <= LogLevel.Warning) {
349+
if (this.checkLogLevel(LogLevel.Warning)) {
345350
this.adapter.log(LogLevel.Warning, [this.extractMessage(message), ...args]);
346351
}
347352
}
348353

349354
error(message: string | Error, ...args: any[]): void {
350-
if (this.getLevel() <= LogLevel.Error) {
355+
if (this.checkLogLevel(LogLevel.Error)) {
351356
this.adapter.log(LogLevel.Error, [this.extractMessage(message), ...args]);
352357
}
353358
}
@@ -357,7 +362,7 @@ export class AdapterLogger extends AbstractLogger implements ILogger {
357362
return msg;
358363
}
359364

360-
return toErrorMessage(msg, this.getLevel() <= LogLevel.Trace);
365+
return toErrorMessage(msg, this.checkLogLevel(LogLevel.Trace));
361366
}
362367

363368
override dispose(): void {

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

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function log(logger: spdlog.Logger, level: LogLevel, message: string): void {
4747
case LogLevel.Info: logger.info(message); break;
4848
case LogLevel.Warning: logger.warn(message); break;
4949
case LogLevel.Error: logger.error(message); break;
50+
case LogLevel.Off: /* do nothing */ break;
5051
default: throw new Error(`Invalid log level ${level}`);
5152
}
5253
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ class TestTelemetryLogger extends AbstractLogger implements ILogger {
1919
}
2020

2121
trace(message: string, ...args: any[]): void {
22-
if (this.getLevel() <= LogLevel.Trace) {
22+
if (this.checkLogLevel(LogLevel.Trace)) {
2323
this.logs.push(message + JSON.stringify(args));
2424
}
2525
}
2626

2727
debug(message: string, ...args: any[]): void {
28-
if (this.getLevel() <= LogLevel.Debug) {
28+
if (this.checkLogLevel(LogLevel.Debug)) {
2929
this.logs.push(message);
3030
}
3131
}
3232

3333
info(message: string, ...args: any[]): void {
34-
if (this.getLevel() <= LogLevel.Info) {
34+
if (this.checkLogLevel(LogLevel.Info)) {
3535
this.logs.push(message);
3636
}
3737
}
3838

3939
warn(message: string | Error, ...args: any[]): void {
40-
if (this.getLevel() <= LogLevel.Warning) {
40+
if (this.checkLogLevel(LogLevel.Warning)) {
4141
this.logs.push(message.toString());
4242
}
4343
}
4444

4545
error(message: string, ...args: any[]): void {
46-
if (this.getLevel() <= LogLevel.Error) {
46+
if (this.checkLogLevel(LogLevel.Error)) {
4747
this.logs.push(message);
4848
}
4949
}

src/vs/server/node/serverServices.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class ServerLogService extends AbstractLogger implements ILogService {
266266
}
267267

268268
trace(message: string, ...args: any[]): void {
269-
if (this.getLevel() <= LogLevel.Trace) {
269+
if (this.checkLogLevel(LogLevel.Trace)) {
270270
if (this.useColors) {
271271
console.log(`\x1b[90m[${now()}]\x1b[0m`, message, ...args);
272272
} else {
@@ -276,7 +276,7 @@ class ServerLogService extends AbstractLogger implements ILogService {
276276
}
277277

278278
debug(message: string, ...args: any[]): void {
279-
if (this.getLevel() <= LogLevel.Debug) {
279+
if (this.checkLogLevel(LogLevel.Debug)) {
280280
if (this.useColors) {
281281
console.log(`\x1b[90m[${now()}]\x1b[0m`, message, ...args);
282282
} else {
@@ -286,7 +286,7 @@ class ServerLogService extends AbstractLogger implements ILogService {
286286
}
287287

288288
info(message: string, ...args: any[]): void {
289-
if (this.getLevel() <= LogLevel.Info) {
289+
if (this.checkLogLevel(LogLevel.Info)) {
290290
if (this.useColors) {
291291
console.log(`\x1b[90m[${now()}]\x1b[0m`, message, ...args);
292292
} else {
@@ -296,7 +296,7 @@ class ServerLogService extends AbstractLogger implements ILogService {
296296
}
297297

298298
warn(message: string | Error, ...args: any[]): void {
299-
if (this.getLevel() <= LogLevel.Warning) {
299+
if (this.checkLogLevel(LogLevel.Warning)) {
300300
if (this.useColors) {
301301
console.warn(`\x1b[93m[${now()}]\x1b[0m`, message, ...args);
302302
} else {
@@ -306,7 +306,7 @@ class ServerLogService extends AbstractLogger implements ILogService {
306306
}
307307

308308
error(message: string, ...args: any[]): void {
309-
if (this.getLevel() <= LogLevel.Error) {
309+
if (this.checkLogLevel(LogLevel.Error)) {
310310
if (this.useColors) {
311311
console.error(`\x1b[91m[${now()}]\x1b[0m`, message, ...args);
312312
} else {

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Codicon } from 'vs/base/common/codicons';
2929
import { Schemas } from 'vs/base/common/network';
3030
import { URI } from 'vs/base/common/uri';
3131
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
32-
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
32+
import { ILogService } from 'vs/platform/log/common/log';
3333
import { INotificationService } from 'vs/platform/notification/common/notification';
3434
import { IShellLaunchConfig, TerminalLocation, TerminalSettingId, WaitOnExitValue } from 'vs/platform/terminal/common/terminal';
3535
import { formatMessageForTerminal } from 'vs/platform/terminal/common/terminalStrings';
@@ -1335,9 +1335,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
13351335
} else {
13361336
for (const terminal of this._reconnectedTerminals) {
13371337
const task = terminal.shellLaunchConfig.attachPersistentProcess?.reconnectionProperties?.data as IReconnectionTaskData;
1338-
if (this._logService.getLevel() <= LogLevel.Trace) {
1339-
this._logService.trace(`Reconnecting to task: ${JSON.stringify(task)}`);
1340-
}
1338+
this._logService.trace(`Reconnecting to task: ${JSON.stringify(task)}`);
13411339
if (!task) {
13421340
continue;
13431341
}

0 commit comments

Comments
 (0)