mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user