From eb426875e9cf7c99b299802c76dc6b1981eddaf0 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 6 Dec 2017 17:49:18 +0100 Subject: [PATCH] logging perf fixes #39808 --- src/vs/platform/log/node/spdlogService.ts | 54 ++++++++++++++--------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/vs/platform/log/node/spdlogService.ts b/src/vs/platform/log/node/spdlogService.ts index e7131d5ece6..06297000854 100644 --- a/src/vs/platform/log/node/spdlogService.ts +++ b/src/vs/platform/log/node/spdlogService.ts @@ -15,7 +15,7 @@ export function createLogService(processName: string, environmentService: IEnvir setAsyncMode(8192, 2000); const logfilePath = path.join(environmentService.logsPath, `${processName}.log`); const logger = new RotatingLogger(processName, logfilePath, 1024 * 1024 * 5, 6); - return new SpdLogService(processName, logger, environmentService.logLevel); + return new SpdLogService(logger, environmentService.logLevel); } catch (e) { console.error(e); } @@ -27,7 +27,6 @@ class SpdLogService implements ILogService { _serviceBrand: any; constructor( - private name: string, private readonly logger: RotatingLogger, private level: LogLevel = LogLevel.Error ) { @@ -41,59 +40,70 @@ class SpdLogService implements ILogService { return this.level; } - trace(message: string, ...args: any[]): void { + trace(): void { if (this.level <= LogLevel.Trace) { - this.logger.trace(this.format(message, args)); + this.logger.trace(this.format(arguments)); } } - debug(message: string, ...args: any[]): void { + debug(): void { if (this.level <= LogLevel.Debug) { - this.logger.debug(this.format(message, args)); + this.logger.debug(this.format(arguments)); } } - info(message: string, ...args: any[]): void { + info(): void { if (this.level <= LogLevel.Info) { - this.logger.info(this.format(message, args)); + this.logger.info(this.format(arguments)); } } - warn(message: string, ...args: any[]): void { + warn(): void { if (this.level <= LogLevel.Warning) { - this.logger.warn(this.format(message, args)); + this.logger.warn(this.format(arguments)); } } - error(arg: string | Error, ...args: any[]): void { + error(): void { if (this.level <= LogLevel.Error) { - const message = arg instanceof Error ? arg.stack : arg; - this.logger.error(this.format(message, args)); + const arg = arguments[0]; + + if (arg instanceof Error) { + const array = Array.prototype.slice.call(arguments) as any[]; + array[0] = arg.stack; + this.logger.error(this.format(array)); + } else { + this.logger.error(this.format(arguments)); + } } } - critical(message: string, ...args: any[]): void { + critical(): void { if (this.level <= LogLevel.Critical) { - this.logger.critical(this.format(message, args)); + this.logger.critical(this.format(arguments)); } } dispose(): void { - this.info('Disposing logger service', this.name); this.logger.flush(); this.logger.drop(); } - private format(value: string, args: any[] = []): string { - const strs = args.map(a => { + private format(args: any): string { + let result = ''; + + for (let i = 0; i < args.length; i++) { + let a = args[i]; + if (typeof a === 'object') { try { - return JSON.stringify(a); + a = JSON.stringify(a); } catch (e) { } } - return a; - }); - return [value, ...strs].join(' '); + result += (i > 0 ? ' ' : '') + a; + } + + return result; } } \ No newline at end of file