Skip to content

Commit 2700f41

Browse files
committed
use desktop and web ext host logging service
1 parent 493d512 commit 2700f41

11 files changed

Lines changed: 160 additions & 69 deletions

File tree

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { OverviewRulerLane } from 'vs/editor/common/model';
1515
import * as languageConfiguration from 'vs/editor/common/modes/languageConfiguration';
1616
import { score } from 'vs/editor/common/modes/languageSelector';
1717
import * as files from 'vs/platform/files/common/files';
18-
import { ExtHostContext, MainContext } from 'vs/workbench/api/common/extHost.protocol';
18+
import { ExtHostContext, MainContext, ExtHostLogServiceShape } from 'vs/workbench/api/common/extHost.protocol';
1919
import { ExtHostApiCommands } from 'vs/workbench/api/common/extHostApiCommands';
2020
import { ExtHostClipboard } from 'vs/workbench/api/common/extHostClipboard';
2121
import { IExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
@@ -33,7 +33,6 @@ import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
3333
import { ExtHostFileSystemEventService } from 'vs/workbench/api/common/extHostFileSystemEventService';
3434
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
3535
import { ExtHostLanguages } from 'vs/workbench/api/common/extHostLanguages';
36-
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
3736
import { ExtHostMessageService } from 'vs/workbench/api/common/extHostMessageService';
3837
import { IExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
3938
import { ExtHostProgress } from 'vs/workbench/api/common/extHostProgress';
@@ -95,10 +94,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
9594
const uriTransformer = accessor.get(IURITransformerService);
9695
const rpcProtocol = accessor.get(IExtHostRpcService);
9796
const extHostStorage = accessor.get(IExtHostStorage);
98-
const extHostLogService = <ExtHostLogService>accessor.get(ILogService);
97+
const extHostLogService = accessor.get(ILogService);
9998

10099
// register addressable instances
101-
rpcProtocol.set(ExtHostContext.ExtHostLogService, extHostLogService);
100+
rpcProtocol.set(ExtHostContext.ExtHostLogService, <ExtHostLogServiceShape><any>extHostLogService);
102101
rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
103102
rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
104103
rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
@@ -145,10 +144,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
145144
const extHostStatusBar = new ExtHostStatusBar(rpcProtocol);
146145
const extHostLanguages = new ExtHostLanguages(rpcProtocol, extHostDocuments);
147146

148-
// Register an output channel for exthost log
149-
const outputChannelName = initData.remote.isRemote ? nls.localize('remote extension host Log', "Remote Extension Host") : nls.localize('extension host Log', "Extension Host");
150-
extHostOutputService.createOutputChannelFromLogFile(outputChannelName, extHostLogService.logFile);
151-
152147
// Register API-ish commands
153148
ExtHostApiCommands.register(extHostCommands);
154149

src/vs/workbench/api/common/extHostExtensionService.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { ILogService } from 'vs/platform/log/common/log';
1414
import { ExtHostExtensionServiceShape, IInitData, MainContext, MainThreadExtensionServiceShape, MainThreadTelemetryShape, MainThreadWorkspaceShape, IResolveAuthorityResult } from 'vs/workbench/api/common/extHost.protocol';
1515
import { ExtHostConfiguration, IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration';
1616
import { ActivatedExtension, EmptyExtension, ExtensionActivatedByAPI, ExtensionActivatedByEvent, ExtensionActivationReason, ExtensionActivationTimes, ExtensionActivationTimesBuilder, ExtensionsActivator, IExtensionAPI, IExtensionContext, IExtensionModule, HostExtension, ExtensionActivationTimesFragment } from 'vs/workbench/api/common/extHostExtensionActivator';
17-
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
1817
import { ExtHostStorage, IExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
1918
import { ExtHostWorkspace, IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
2019
import { ExtensionActivationError } from 'vs/workbench/services/extensions/common/extensions';
@@ -75,7 +74,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
7574
protected readonly _instaService: IInstantiationService;
7675
protected readonly _extHostWorkspace: ExtHostWorkspace;
7776
protected readonly _extHostConfiguration: ExtHostConfiguration;
78-
protected readonly _extHostLogService: ExtHostLogService;
77+
protected readonly _logService: ILogService;
7978

8079
protected readonly _mainThreadWorkspaceProxy: MainThreadWorkspaceShape;
8180
protected readonly _mainThreadTelemetryProxy: MainThreadTelemetryShape;
@@ -102,7 +101,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
102101
@IExtHostRpcService extHostContext: IExtHostRpcService,
103102
@IExtHostWorkspace extHostWorkspace: IExtHostWorkspace,
104103
@IExtHostConfiguration extHostConfiguration: IExtHostConfiguration,
105-
@ILogService extHostLogService: ExtHostLogService,
104+
@ILogService logService: ILogService,
106105
@IExtHostInitDataService initData: IExtHostInitDataService,
107106
@IExtensionStoragePaths storagePath: IExtensionStoragePaths
108107
) {
@@ -112,7 +111,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
112111

113112
this._extHostWorkspace = extHostWorkspace;
114113
this._extHostConfiguration = extHostConfiguration;
115-
this._extHostLogService = extHostLogService;
114+
this._logService = logService;
116115
this._disposables = new DisposableStore();
117116

118117
this._mainThreadWorkspaceProxy = this._extHostContext.getProxy(MainContext.MainThreadWorkspace);
@@ -329,14 +328,14 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
329328
return Promise.resolve(new EmptyExtension(ExtensionActivationTimes.NONE));
330329
}
331330

332-
this._extHostLogService.info(`ExtensionService#_doActivateExtension ${extensionDescription.identifier.value} ${JSON.stringify(reason)}`);
331+
this._logService.info(`ExtensionService#_doActivateExtension ${extensionDescription.identifier.value} ${JSON.stringify(reason)}`);
333332

334333
const activationTimesBuilder = new ExtensionActivationTimesBuilder(reason.startup);
335334
return Promise.all<any>([
336335
this._loadCommonJSModule(extensionDescription.main, activationTimesBuilder),
337336
this._loadExtensionContext(extensionDescription)
338337
]).then(values => {
339-
return AbstractExtHostExtensionService._callActivate(this._extHostLogService, extensionDescription.identifier, <IExtensionModule>values[0], <IExtensionContext>values[1], activationTimesBuilder);
338+
return AbstractExtHostExtensionService._callActivate(this._logService, extensionDescription.identifier, <IExtensionModule>values[0], <IExtensionContext>values[1], activationTimesBuilder);
340339
});
341340
}
342341

@@ -347,7 +346,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
347346
const globalState = new ExtensionMemento(extensionDescription.identifier.value, true, this._storage);
348347
const workspaceState = new ExtensionMemento(extensionDescription.identifier.value, false, this._storage);
349348

350-
this._extHostLogService.trace(`ExtensionService#loadExtensionContext ${extensionDescription.identifier.value}`);
349+
this._logService.trace(`ExtensionService#loadExtensionContext ${extensionDescription.identifier.value}`);
351350
return Promise.all([
352351
globalState.whenReady,
353352
workspaceState.whenReady,
@@ -359,10 +358,10 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
359358
workspaceState,
360359
subscriptions: [],
361360
get extensionPath() { return extensionDescription.extensionLocation.fsPath; },
362-
storagePath: this._storagePath.workspaceValue(extensionDescription),
363-
globalStoragePath: this._storagePath.globalValue(extensionDescription),
361+
get storagePath() { return that._storagePath.workspaceValue(extensionDescription); },
362+
get globalStoragePath() { return that._storagePath.globalValue(extensionDescription); },
364363
asAbsolutePath: (relativePath: string) => { return path.join(extensionDescription.extensionLocation.fsPath, relativePath); },
365-
logPath: that._extHostLogService.getLogDirectory(extensionDescription.identifier),
364+
get logPath() { return path.join(that._initData.logsLocation.fsPath, extensionDescription.identifier.value); },
366365
executionContext: this._initData.remote.isRemote ? ExtensionExecutionContext.Remote : ExtensionExecutionContext.Local,
367366
});
368367
});
@@ -479,7 +478,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
479478
}
480479

481480
private async _activateIfGlobPatterns(folders: ReadonlyArray<vscode.WorkspaceFolder>, extensionId: ExtensionIdentifier, globPatterns: string[]): Promise<void> {
482-
this._extHostLogService.trace(`extensionHostMain#activateIfGlobPatterns: fileSearch, extension: ${extensionId.value}, entryPoint: workspaceContains`);
481+
this._logService.trace(`extensionHostMain#activateIfGlobPatterns: fileSearch, extension: ${extensionId.value}, entryPoint: workspaceContains`);
483482

484483
if (globPatterns.length === 0) {
485484
return Promise.resolve(undefined);
@@ -606,7 +605,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
606605
.then(() => this._handleEagerExtensions())
607606
.then(() => this._handleExtensionTests())
608607
.then(() => {
609-
this._extHostLogService.info(`eager extensions activated`);
608+
this._logService.info(`eager extensions activated`);
610609
});
611610
}
612611

src/vs/workbench/api/common/extHostLogService.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/vs/workbench/api/node/extHost.services.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePa
2424
import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
2525
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
2626
import { IExtHostStorage, ExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
27+
import { ILogService } from 'vs/platform/log/common/log';
28+
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
2729

2830
// register singleton services
31+
registerSingleton(ILogService, ExtHostLogService);
2932
registerSingleton(IExtHostOutputService, ExtHostOutputService2);
3033
registerSingleton(IExtHostWorkspace, ExtHostWorkspace);
3134
registerSingleton(IExtHostDecorations, ExtHostDecorations);

src/vs/workbench/api/node/extHostExtensionService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
4141
}
4242

4343
// Do this when extension service exists, but extensions are not being activated yet.
44-
await connectProxyResolver(this._extHostWorkspace, configProvider, this, this._extHostLogService, this._mainThreadTelemetryProxy);
44+
await connectProxyResolver(this._extHostWorkspace, configProvider, this, this._logService, this._mainThreadTelemetryProxy);
4545

4646
}
4747

4848
protected _loadCommonJSModule<T>(modulePath: string, activationTimesBuilder: ExtensionActivationTimesBuilder): Promise<T> {
4949
let r: T | null = null;
5050
activationTimesBuilder.codeLoadingStart();
51-
this._extHostLogService.info(`ExtensionService#loadCommonJSModule ${modulePath}`);
51+
this._logService.info(`ExtensionService#loadCommonJSModule ${modulePath}`);
5252
try {
5353
r = require.__$__nodeRequire<T>(modulePath);
5454
} catch (e) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { localize } from 'vs/nls';
7+
import { join } from 'vs/base/common/path';
8+
import { ILogService, DelegatedLogService, LogLevel } from 'vs/platform/log/common/log';
9+
import { ExtHostLogServiceShape } from 'vs/workbench/api/common/extHost.protocol';
10+
import { ExtensionHostLogFileName } from 'vs/workbench/services/extensions/common/extensions';
11+
import { URI } from 'vs/base/common/uri';
12+
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
13+
import { Schemas } from 'vs/base/common/network';
14+
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
15+
import { IExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
16+
17+
export class ExtHostLogService extends DelegatedLogService implements ILogService, ExtHostLogServiceShape {
18+
19+
constructor(
20+
@IExtHostInitDataService initData: IExtHostInitDataService,
21+
@IExtHostOutputService extHostOutputService: IExtHostOutputService
22+
) {
23+
if (initData.logsLocation.scheme !== Schemas.file) { throw new Error('Only file-logging supported'); }
24+
super(new SpdLogService(ExtensionHostLogFileName, initData.logsLocation.fsPath, initData.logLevel));
25+
26+
// Register an output channel for exthost log
27+
extHostOutputService.createOutputChannelFromLogFile(
28+
initData.remote.isRemote ? localize('remote extension host Log', "Remote Extension Host") : localize('extension host Log', "Extension Host"),
29+
URI.file(join(initData.logsLocation.fsPath, `${ExtensionHostLogFileName}.log`))
30+
);
31+
}
32+
33+
$setLevel(level: LogLevel): void {
34+
this.setLevel(level);
35+
}
36+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { ILogService, LogLevel, AbstractLogService } from 'vs/platform/log/common/log';
7+
import { ExtHostLogServiceShape } from 'vs/workbench/api/common/extHost.protocol';
8+
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
9+
import { IExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
10+
import * as vscode from 'vscode';
11+
12+
export class ExtHostLogService extends AbstractLogService implements ILogService, ExtHostLogServiceShape {
13+
14+
_serviceBrand: any;
15+
16+
private readonly _logChannel: vscode.OutputChannel;
17+
18+
constructor(
19+
@IExtHostInitDataService initData: IExtHostInitDataService,
20+
@IExtHostOutputService extHostOutputService: IExtHostOutputService
21+
) {
22+
super();
23+
this.setLevel(initData.logLevel);
24+
this._logChannel = extHostOutputService.createOutputChannel('Log (Worker Extension Host)');
25+
}
26+
27+
$setLevel(level: LogLevel): void {
28+
this.setLevel(level);
29+
}
30+
31+
trace(_message: string, ..._args: any[]): void {
32+
if (this.getLevel() <= LogLevel.Trace) {
33+
this._logChannel.appendLine(this._format(arguments));
34+
}
35+
}
36+
37+
debug(_message: string, ..._args: any[]): void {
38+
if (this.getLevel() <= LogLevel.Debug) {
39+
this._logChannel.appendLine(this._format(arguments));
40+
}
41+
}
42+
43+
info(_message: string, ..._args: any[]): void {
44+
if (this.getLevel() <= LogLevel.Info) {
45+
this._logChannel.appendLine(this._format(arguments));
46+
}
47+
}
48+
49+
warn(_message: string, ..._args: any[]): void {
50+
if (this.getLevel() <= LogLevel.Warning) {
51+
this._logChannel.appendLine(this._format(arguments));
52+
}
53+
}
54+
55+
error(_message: string | Error, ..._args: any[]): void {
56+
if (this.getLevel() <= LogLevel.Error) {
57+
this._logChannel.appendLine(this._format(arguments));
58+
}
59+
}
60+
61+
critical(_message: string | Error, ..._args: any[]): void {
62+
if (this.getLevel() <= LogLevel.Critical) {
63+
this._logChannel.appendLine(String(arguments));
64+
}
65+
}
66+
67+
private _format(args: any): string {
68+
let result = '';
69+
70+
for (let i = 0; i < args.length; i++) {
71+
let a = args[i];
72+
73+
if (typeof a === 'object') {
74+
try {
75+
a = JSON.stringify(a);
76+
} catch (e) { }
77+
}
78+
79+
result += (i > 0 ? ' ' : '') + a;
80+
}
81+
82+
return result;
83+
}
84+
}

src/vs/workbench/services/extensions/common/extensionHostMain.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { URI, setUriThrowOnMissingScheme } from 'vs/base/common/uri';
1010
import { IURITransformer } from 'vs/base/common/uriIpc';
1111
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
1212
import { IInitData, MainContext, MainThreadConsoleShape } from 'vs/workbench/api/common/extHost.protocol';
13-
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
1413
import { RPCProtocol } from 'vs/workbench/services/extensions/common/rpcProtocol';
1514
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
1615
import { ILogService } from 'vs/platform/log/common/log';
@@ -65,21 +64,21 @@ export class ExtensionHostMain {
6564
consolePatchFn(rpcProtocol.getProxy(MainContext.MainThreadConsole));
6665

6766
// services
68-
const extHostLogService = new ExtHostLogService(logServiceFn(initData), initData.logsLocation.fsPath);
69-
this._disposables.add(extHostLogService);
7067

7168
// bootstrap services
7269
const services = new ServiceCollection(...getSingletonServiceDescriptors());
7370
services.set(IExtHostInitDataService, { _serviceBrand: undefined, ...initData });
7471
services.set(IExtHostRpcService, new ExtHostRpcService(rpcProtocol));
75-
services.set(ILogService, extHostLogService);
7672
services.set(IURITransformerService, new URITransformerService(uriTransformer));
7773
services.set(IHostUtils, hostUtils);
7874

7975
const instaService: IInstantiationService = new InstantiationService(services, true);
8076

81-
extHostLogService.info('extension host started');
82-
extHostLogService.trace('initData', initData);
77+
const logService = instaService.invokeFunction(accessor => accessor.get(ILogService));
78+
this._disposables.add(logService);
79+
80+
logService.info('extension host started');
81+
logService.trace('initData', initData);
8382

8483
// todo@joh -> not soo nice...
8584
this._extensionService = instaService.invokeFunction(accessor => accessor.get(IExtHostExtensionService));

0 commit comments

Comments
 (0)