Ability to create log file channels from extension host

This commit is contained in:
Sandeep Somavarapu
2018-09-07 11:51:48 +02:00
parent dc4c763127
commit c1a6295edf
9 changed files with 57 additions and 49 deletions

View File

@@ -61,6 +61,7 @@ import { ExtHostWebviews } from 'vs/workbench/api/node/extHostWebview';
import { ExtHostComments } from './extHostComments';
import { ExtHostSearch } from './extHostSearch';
import { ExtHostUrls } from './extHostUrls';
import { localize } from 'vs/nls';
export interface IExtensionApiFactory {
(extension: IExtensionDescription): typeof vscode;
@@ -139,6 +140,9 @@ export function createApiFactory(
const extHostOutputService = new ExtHostOutputService(initData.logsLocation, rpcProtocol);
const extHostLanguages = new ExtHostLanguages(rpcProtocol);
// Register an output channel for exthost log
extHostOutputService.createOutputChannelFromLogFile(localize('extensionsLog', "Extension Host"), extHostLogService.logFile);
// Register API-ish commands
ExtHostApiCommands.register(extHostCommands);

View File

@@ -300,7 +300,7 @@ export interface MainThreadMessageServiceShape extends IDisposable {
}
export interface MainThreadOutputServiceShape extends IDisposable {
$register(label: string, file?: UriComponents): Thenable<string>;
$register(label: string, log: boolean, file?: UriComponents): Thenable<string>;
$append(channelId: string, value: string): Thenable<void>;
$clear(channelId: string): Thenable<void>;
$reveal(channelId: string, preserveFocus: boolean): Thenable<void>;

View File

@@ -10,11 +10,13 @@ import { ILogService, DelegatedLogService } from 'vs/platform/log/common/log';
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
import { ExtHostLogServiceShape } from 'vs/workbench/api/node/extHost.protocol';
import { ExtensionHostLogFileName } from 'vs/workbench/services/extensions/common/extensions';
import { URI } from 'vs/base/common/uri';
export class ExtHostLogService extends DelegatedLogService implements ILogService, ExtHostLogServiceShape {
private _logsPath: string;
readonly logFile: URI;
constructor(
logLevel: LogLevel,
@@ -22,6 +24,7 @@ export class ExtHostLogService extends DelegatedLogService implements ILogServic
) {
super(createSpdLogService(ExtensionHostLogFileName, logLevel, logsPath));
this._logsPath = logsPath;
this.logFile = URI.file(join(logsPath, `${ExtensionHostLogFileName}.log`));
}
$setLevel(level: LogLevel): void {

View File

@@ -18,10 +18,10 @@ export abstract class AbstractExtHostOutputChannel implements vscode.OutputChann
protected readonly _proxy: MainThreadOutputServiceShape;
private _disposed: boolean;
constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
constructor(name: string, log: boolean, file: URI, proxy: MainThreadOutputServiceShape) {
this._name = name;
this._proxy = proxy;
this._id = proxy.$register(this.name, file);
this._id = proxy.$register(this.name, log, file);
}
get name(): string {
@@ -68,7 +68,7 @@ export abstract class AbstractExtHostOutputChannel implements vscode.OutputChann
export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {
constructor(name: string, proxy: MainThreadOutputServiceShape) {
super(name, null, proxy);
super(name, false, null, proxy);
}
append(value: string): void {
@@ -77,16 +77,16 @@ export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {
}
}
export class ExtHostFileOutputChannel extends AbstractExtHostOutputChannel {
export class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
private static _namePool = 1;
private _appender: OutputAppender;
constructor(name: string, outputDir: string, proxy: MainThreadOutputServiceShape) {
const fileName = `${ExtHostFileOutputChannel._namePool++}-${name}`;
const fileName = `${ExtHostOutputChannelBackedByFile._namePool++}-${name}`;
const file = URI.file(posix.join(outputDir, `${fileName}.log`));
super(name, file, proxy);
super(name, false, file, proxy);
this._appender = new OutputAppender(fileName, file.fsPath);
}
@@ -96,6 +96,17 @@ export class ExtHostFileOutputChannel extends AbstractExtHostOutputChannel {
}
}
export class ExtHostLogFileOutputChannel extends AbstractExtHostOutputChannel {
constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
super(name, true, file, proxy);
}
append(value: string): void {
throw new Error('Not supported');
}
}
export class ExtHostOutputService {
private _proxy: MainThreadOutputServiceShape;
@@ -116,7 +127,7 @@ export class ExtHostOutputService {
} else {
// Do not crash if logger cannot be created
try {
return new ExtHostFileOutputChannel(name, this._outputDir, this._proxy);
return new ExtHostOutputChannelBackedByFile(name, this._outputDir, this._proxy);
} catch (error) {
console.log(error);
return new ExtHostPushOutputChannel(name, this._proxy);
@@ -124,4 +135,15 @@ export class ExtHostOutputService {
}
}
}
createOutputChannelFromLogFile(name: string, file: URI): vscode.OutputChannel {
name = name.trim();
if (!name) {
throw new Error('illegal argument `name`. must not be falsy');
}
if (!file) {
throw new Error('illegal argument `file`. must not be falsy');
}
return new ExtHostLogFileOutputChannel(name, file, this._proxy);
}
}