support passing extension log level from cli (#163566)

This commit is contained in:
Sandeep Somavarapu
2022-10-13 18:21:47 +02:00
committed by GitHub
parent af4b19dd24
commit 2b50ab06b1
18 changed files with 125 additions and 67 deletions

View File

@@ -20,7 +20,7 @@ export class ExtHostLoggerService extends AbstractLoggerService implements ExtHo
@IExtHostRpcService rpc: IExtHostRpcService,
@IExtHostInitDataService initData: IExtHostInitDataService,
) {
super(initData.logLevel, Event.None, []);
super(initData.logLevel, Event.None);
this._proxy = rpc.getProxy(MainContext.MainThreadLogger);
}

View File

@@ -8,8 +8,8 @@ import type * as vscode from 'vscode';
import { URI } from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { AbstractMessageLogger, ILogger, ILoggerService, ILogService, log, LogLevel } from 'vs/platform/log/common/log';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { AbstractMessageLogger, ILogger, ILoggerService, ILogService, log, LogLevel, parseLogLevel } from 'vs/platform/log/common/log';
import { OutputChannelUpdateMode } from 'vs/workbench/services/output/common/output';
import { IExtHostConsumerFileSystem } from 'vs/workbench/api/common/extHostFileSystemConsumer';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
@@ -151,12 +151,13 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
if (isString(languageId) && !languageId.trim()) {
throw new Error('illegal argument `languageId`. must not be empty');
}
const extHostOutputChannel = log ? this.doCreateLogOutputChannel(name, extension) : this.doCreateOutputChannel(name, languageId, extension);
const logLevel = this.getDefaultLogLevel(extension);
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, <Promise<ExtHostOutputChannel>>extHostOutputChannel) : this.createExtHostOutputChannel(name, <Promise<ExtHostOutputChannel>>extHostOutputChannel);
return log ? this.createExtHostLogOutputChannel(name, logLevel, <Promise<ExtHostOutputChannel>>extHostOutputChannel) : this.createExtHostOutputChannel(name, <Promise<ExtHostOutputChannel>>extHostOutputChannel);
}
private async doCreateOutputChannel(name: string, languageId: string | undefined, extension: IExtensionDescription): Promise<ExtHostOutputChannel> {
@@ -170,14 +171,23 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
return new ExtHostOutputChannel(id, name, logger, this.proxy, extension);
}
private async doCreateLogOutputChannel(name: string, extension: IExtensionDescription): Promise<ExtHostLogOutputChannel> {
private async doCreateLogOutputChannel(name: string, logLevel: LogLevel, 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 });
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) {
@@ -236,14 +246,13 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
};
}
private createExtHostLogOutputChannel(name: string, channelPromise: Promise<ExtHostOutputChannel>): vscode.LogOutputChannel {
private createExtHostLogOutputChannel(name: string, logLevel: LogLevel, channelPromise: Promise<ExtHostOutputChannel>): vscode.LogOutputChannel {
const disposables = new DisposableStore();
const validate = () => {
if (disposables.isDisposed) {
throw new Error('Channel has been closed');
}
};
let logLevel = this.logService.getLevel();
const onDidChangeLogLevel = disposables.add(new Emitter<LogLevel>());
channelPromise.then(channel => {
disposables.add(channel);