Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored and formigoni committed Oct 27, 2022
1 parent 89c0058 commit 2ca3b08
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/vs/workbench/api/common/extHostOutput.ts
Expand Up @@ -151,13 +151,17 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
if (isString(languageId) && !languageId.trim()) {
throw new Error('illegal argument `languageId`. must not be empty');
}
const logLevel = this.getDefaultLogLevel(extension);
let logLevel: LogLevel | undefined;
const logLevelValue = this.initData.environment.extensionLogLevel?.find(([identifier]) => ExtensionIdentifier.equals(extension.identifier, identifier))?.[1];
if (logLevelValue) {
logLevel = parseLogLevel(logLevelValue);
}
const extHostOutputChannel = log ? this.doCreateLogOutputChannel(name, logLevel, extension) : this.doCreateOutputChannel(name, languageId, extension);
extHostOutputChannel.then(channel => {
this.channels.set(channel.id, channel);
channel.visible = channel.id === this.visibleChannelId;
});
return log ? this.createExtHostLogOutputChannel(name, logLevel, <Promise<ExtHostOutputChannel>>extHostOutputChannel) : this.createExtHostOutputChannel(name, <Promise<ExtHostOutputChannel>>extHostOutputChannel);
return log ? this.createExtHostLogOutputChannel(name, logLevel ?? this.logService.getLevel(), <Promise<ExtHostOutputChannel>>extHostOutputChannel) : this.createExtHostOutputChannel(name, <Promise<ExtHostOutputChannel>>extHostOutputChannel);
}

private async doCreateOutputChannel(name: string, languageId: string | undefined, extension: IExtensionDescription): Promise<ExtHostOutputChannel> {
Expand All @@ -171,23 +175,14 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
return new ExtHostOutputChannel(id, name, logger, this.proxy, extension);
}

private async doCreateLogOutputChannel(name: string, logLevel: LogLevel, extension: IExtensionDescription): Promise<ExtHostLogOutputChannel> {
private async doCreateLogOutputChannel(name: string, logLevel: LogLevel | undefined, extension: IExtensionDescription): Promise<ExtHostLogOutputChannel> {
const extensionLogDir = await this.createExtensionLogDirectory(extension);
const file = this.extHostFileSystemInfo.extUri.joinPath(extensionLogDir, `${name.replace(/[\\/:\*\?"<>\|]/g, '')}.log`);
const logger = this.loggerService.createLogger(file, { name }, logLevel);
const id = await this.proxy.$register(name, file, true, undefined, extension.identifier.value);
return new ExtHostLogOutputChannel(id, name, logger, this.proxy, extension);
}

private getDefaultLogLevel(extension: IExtensionDescription): LogLevel {
let logLevel: LogLevel | undefined;
const logLevelValue = this.initData.environment.extensionLogLevel?.find(([identifier]) => ExtensionIdentifier.equals(extension.identifier, identifier))?.[1];
if (logLevelValue) {
logLevel = parseLogLevel(logLevelValue);
}
return logLevel ?? this.logService.getLevel();
}

private createExtensionLogDirectory(extension: IExtensionDescription): Thenable<URI> {
let extensionLogDirectoryPromise = this.extensionLogDirectoryPromise.get(extension.identifier.value);
if (!extensionLogDirectoryPromise) {
Expand Down

0 comments on commit 2ca3b08

Please sign in to comment.