respect donotUseFormatters option

This commit is contained in:
Sandeep Somavarapu 2021-07-16 16:13:06 +02:00
parent 57a5370b5d
commit cb572547d2
3 changed files with 11 additions and 6 deletions

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ILogService, LogLevel, AbstractLogger, ILoggerService, ILogger, AbstractLoggerService } from 'vs/platform/log/common/log';
import { ILogService, LogLevel, AbstractLogger, ILoggerService, ILogger, AbstractLoggerService, ILoggerOptions } from 'vs/platform/log/common/log';
import { URI } from 'vs/base/common/uri';
import { ByteSize, FileOperationError, FileOperationResult, IFileService, whenProviderRegistered } from 'vs/platform/files/common/files';
import { Queue } from 'vs/base/common/async';
@ -24,6 +24,7 @@ export class FileLogger extends AbstractLogger implements ILogger {
private readonly name: string,
private readonly resource: URI,
level: LogLevel,
private readonly donotUseFormatters: boolean,
@IFileService private readonly fileService: IFileService
) {
super();
@ -101,7 +102,11 @@ export class FileLogger extends AbstractLogger implements ILogger {
await this.fileService.writeFile(this.getBackupResource(), VSBuffer.fromString(content));
content = '';
}
content += `[${this.getCurrentTimestamp()}] [${this.name}] [${this.stringifyLogLevel(level)}] ${message}\n`;
if (this.donotUseFormatters) {
content += message;
} else {
content += `[${this.getCurrentTimestamp()}] [${this.name}] [${this.stringifyLogLevel(level)}] ${message}\n`;
}
await this.fileService.writeFile(this.resource, VSBuffer.fromString(content));
});
}
@ -168,9 +173,9 @@ export class FileLoggerService extends AbstractLoggerService implements ILoggerS
super(logService.getLevel(), logService.onDidChangeLogLevel);
}
protected doCreateLogger(resource: URI, logLevel: LogLevel): ILogger {
protected doCreateLogger(resource: URI, logLevel: LogLevel, options?: ILoggerOptions): ILogger {
const logger = new BufferLogService(logLevel);
whenProviderRegistered(resource, this.fileService).then(() => (<BufferLogService>logger).logger = this.instantiationService.createInstance(FileLogger, basename(resource), resource, logger.getLevel()));
whenProviderRegistered(resource, this.fileService).then(() => (<BufferLogService>logger).logger = this.instantiationService.createInstance(FileLogger, basename(resource), resource, logger.getLevel(), !!options?.donotUseFormatters));
return logger;
}
}

View file

@ -29,7 +29,7 @@ export class LoggerService extends AbstractLoggerService implements ILoggerServi
}
return logger;
} else {
return new FileLogger(options?.name ?? basename(resource), resource, logLevel, this.fileService);
return new FileLogger(options?.name ?? basename(resource), resource, logLevel, !!options?.donotUseFormatters, this.fileService);
}
}
}

View file

@ -269,7 +269,7 @@ class BrowserMain extends Disposable {
logService.logger = new MultiplexLogService(coalesce([
new ConsoleLogger(logService.getLevel()),
new FileLogger('window', environmentService.logFile, logService.getLevel(), fileService),
new FileLogger('window', environmentService.logFile, logService.getLevel(), false, fileService),
// Extension development test CLI: forward everything to test runner
environmentService.isExtensionDevelopment && !!environmentService.extensionTestsLocationURI ? new ConsoleLogInAutomationLogger(logService.getLevel()) : undefined
]));