Skip to content

Commit eb42687

Browse files
committed
logging perf
fixes microsoft#39808
1 parent 8c2bd8b commit eb42687

1 file changed

Lines changed: 32 additions & 22 deletions

File tree

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

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createLogService(processName: string, environmentService: IEnvir
1515
setAsyncMode(8192, 2000);
1616
const logfilePath = path.join(environmentService.logsPath, `${processName}.log`);
1717
const logger = new RotatingLogger(processName, logfilePath, 1024 * 1024 * 5, 6);
18-
return new SpdLogService(processName, logger, environmentService.logLevel);
18+
return new SpdLogService(logger, environmentService.logLevel);
1919
} catch (e) {
2020
console.error(e);
2121
}
@@ -27,7 +27,6 @@ class SpdLogService implements ILogService {
2727
_serviceBrand: any;
2828

2929
constructor(
30-
private name: string,
3130
private readonly logger: RotatingLogger,
3231
private level: LogLevel = LogLevel.Error
3332
) {
@@ -41,59 +40,70 @@ class SpdLogService implements ILogService {
4140
return this.level;
4241
}
4342

44-
trace(message: string, ...args: any[]): void {
43+
trace(): void {
4544
if (this.level <= LogLevel.Trace) {
46-
this.logger.trace(this.format(message, args));
45+
this.logger.trace(this.format(arguments));
4746
}
4847
}
4948

50-
debug(message: string, ...args: any[]): void {
49+
debug(): void {
5150
if (this.level <= LogLevel.Debug) {
52-
this.logger.debug(this.format(message, args));
51+
this.logger.debug(this.format(arguments));
5352
}
5453
}
5554

56-
info(message: string, ...args: any[]): void {
55+
info(): void {
5756
if (this.level <= LogLevel.Info) {
58-
this.logger.info(this.format(message, args));
57+
this.logger.info(this.format(arguments));
5958
}
6059
}
6160

62-
warn(message: string, ...args: any[]): void {
61+
warn(): void {
6362
if (this.level <= LogLevel.Warning) {
64-
this.logger.warn(this.format(message, args));
63+
this.logger.warn(this.format(arguments));
6564
}
6665
}
6766

68-
error(arg: string | Error, ...args: any[]): void {
67+
error(): void {
6968
if (this.level <= LogLevel.Error) {
70-
const message = arg instanceof Error ? arg.stack : arg;
71-
this.logger.error(this.format(message, args));
69+
const arg = arguments[0];
70+
71+
if (arg instanceof Error) {
72+
const array = Array.prototype.slice.call(arguments) as any[];
73+
array[0] = arg.stack;
74+
this.logger.error(this.format(array));
75+
} else {
76+
this.logger.error(this.format(arguments));
77+
}
7278
}
7379
}
7480

75-
critical(message: string, ...args: any[]): void {
81+
critical(): void {
7682
if (this.level <= LogLevel.Critical) {
77-
this.logger.critical(this.format(message, args));
83+
this.logger.critical(this.format(arguments));
7884
}
7985
}
8086

8187
dispose(): void {
82-
this.info('Disposing logger service', this.name);
8388
this.logger.flush();
8489
this.logger.drop();
8590
}
8691

87-
private format(value: string, args: any[] = []): string {
88-
const strs = args.map(a => {
92+
private format(args: any): string {
93+
let result = '';
94+
95+
for (let i = 0; i < args.length; i++) {
96+
let a = args[i];
97+
8998
if (typeof a === 'object') {
9099
try {
91-
return JSON.stringify(a);
100+
a = JSON.stringify(a);
92101
} catch (e) { }
93102
}
94-
return a;
95-
});
96103

97-
return [value, ...strs].join(' ');
104+
result += (i > 0 ? ' ' : '') + a;
105+
}
106+
107+
return result;
98108
}
99109
}

0 commit comments

Comments
 (0)