提交 857ab9d5 编写于 作者: J Joao Moreno

use global log service

上级 83c6d5ab
......@@ -36,7 +36,7 @@ import { ipcRenderer } from 'electron';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { createSharedProcessContributions } from 'vs/code/electron-browser/contrib/contributions';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import { ILogService } from 'vs/platform/log/common/log';
import { ILogService, registerGlobalLogService } from 'vs/platform/log/common/log';
export interface ISharedProcessConfiguration {
readonly machineId: string;
......@@ -80,6 +80,8 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
const environmentService = new EnvironmentService(initData.args, process.execPath);
const logService = new SpdLogService('sharedprocess', environmentService);
registerGlobalLogService(logService);
logService.info('main', JSON.stringify(configuration));
services.set(IEnvironmentService, environmentService);
......
......@@ -20,7 +20,7 @@ import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiati
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ILogService, LegacyLogMainService, MultiplexLogService } from 'vs/platform/log/common/log';
import { ILogService, LegacyLogMainService, MultiplexLogService, registerGlobalLogService } from 'vs/platform/log/common/log';
import { StateService } from 'vs/platform/state/node/stateService';
import { IStateService } from 'vs/platform/state/common/state';
import { IBackupMainService } from 'vs/platform/backup/common/backup';
......@@ -51,6 +51,7 @@ function createServices(args: ParsedArgs): IInstantiationService {
const spdlogService = new SpdLogService('main', environmentService);
const legacyLogService = new LegacyLogMainService(environmentService);
const logService = new MultiplexLogService([legacyLogService, spdlogService]);
registerGlobalLogService(logService);
// Eventually cleanup
setTimeout(() => spdlogService.cleanup().then(null, err => console.error(err)), 10000);
......
......@@ -11,7 +11,7 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import Event, { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { log, LogLevel, ILogService } from 'vs/platform/log/common/log';
import { log, LogLevel } from 'vs/platform/log/common/log';
export class CommandService extends Disposable implements ICommandService {
......@@ -25,9 +25,7 @@ export class CommandService extends Disposable implements ICommandService {
constructor(
@IInstantiationService private _instantiationService: IInstantiationService,
@IExtensionService private _extensionService: IExtensionService,
@IContextKeyService private _contextKeyService: IContextKeyService,
// @ts-ignore
@ILogService private logService: ILogService
@IContextKeyService private _contextKeyService: IContextKeyService
) {
super();
this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value);
......
......@@ -16,7 +16,6 @@ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyServ
import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import Event, { Emitter } from 'vs/base/common/event';
import { NoopLogService } from 'vs/platform/log/common/log';
class SimpleExtensionService implements IExtensionService {
_serviceBrand: any;
......@@ -75,7 +74,7 @@ suite('CommandService', function () {
lastEvent = activationEvent;
return super.activateByEvent(activationEvent);
}
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
}, new ContextKeyService(new SimpleConfigurationService()));
return service.executeCommand('foo').then(() => {
assert.ok(lastEvent, 'onCommand:foo');
......@@ -93,7 +92,7 @@ suite('CommandService', function () {
activateByEvent(activationEvent: string): TPromise<void> {
return TPromise.wrapError<void>(new Error('bad_activate'));
}
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
}, new ContextKeyService(new SimpleConfigurationService()));
return service.executeCommand('foo').then(() => assert.ok(false), err => {
assert.equal(err.message, 'bad_activate');
......@@ -109,7 +108,7 @@ suite('CommandService', function () {
whenInstalledExtensionsRegistered() {
return new TPromise<boolean>(_resolve => { /*ignore*/ });
}
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
}, new ContextKeyService(new SimpleConfigurationService()));
service.executeCommand('bar');
assert.equal(callCounter, 1);
......@@ -126,7 +125,7 @@ suite('CommandService', function () {
whenInstalledExtensionsRegistered() {
return new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
}
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
}, new ContextKeyService(new SimpleConfigurationService()));
let r = service.executeCommand('bar');
assert.equal(callCounter, 0);
......@@ -145,8 +144,7 @@ suite('CommandService', function () {
let commandService = new CommandService(
new InstantiationService(),
new SimpleExtensionService(),
contextKeyService,
new NoopLogService()
contextKeyService
);
let counter = 0;
......
......@@ -107,6 +107,22 @@ export class MultiplexLogService implements ILogService {
}
}
export class NoopLogService implements ILogService {
_serviceBrand: any;
trace(message: string, ...args: any[]): void { }
debug(message: string, ...args: any[]): void { }
info(message: string, ...args: any[]): void { }
warn(message: string, ...args: any[]): void { }
error(message: string | Error, ...args: any[]): void { }
critical(message: string | Error, ...args: any[]): void { }
}
let globalLogService: ILogService = new NoopLogService();
export function registerGlobalLogService(logService: ILogService): void {
globalLogService = logService;
}
export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function {
return createDecorator((fn, key) => {
// TODO@Joao: load-time log level? return fn;
......@@ -119,25 +135,15 @@ export function log(level: LogLevel, prefix: string, logFn?: (message: string, .
}
switch (level) {
case LogLevel.TRACE: this.logService.trace(message); break;
case LogLevel.DEBUG: this.logService.debug(message); break;
case LogLevel.INFO: this.logService.info(message); break;
case LogLevel.WARN: this.logService.warn(message); break;
case LogLevel.ERROR: this.logService.error(message); break;
case LogLevel.CRITICAL: this.logService.critical(message); break;
case LogLevel.TRACE: globalLogService.trace(message); break;
case LogLevel.DEBUG: globalLogService.debug(message); break;
case LogLevel.INFO: globalLogService.info(message); break;
case LogLevel.WARN: globalLogService.warn(message); break;
case LogLevel.ERROR: globalLogService.error(message); break;
case LogLevel.CRITICAL: globalLogService.critical(message); break;
}
return fn.apply(this, args);
};
});
}
export class NoopLogService implements ILogService {
_serviceBrand: any;
trace(message: string, ...args: any[]): void { }
debug(message: string, ...args: any[]): void { }
info(message: string, ...args: any[]): void { }
warn(message: string, ...args: any[]): void { }
error(message: string | Error, ...args: any[]): void { }
critical(message: string | Error, ...args: any[]): void { }
}
\ No newline at end of file
......@@ -57,7 +57,6 @@ import { FileChangeType, FileType } from 'vs/platform/files/common/files';
import { ExtHostDecorations } from 'vs/workbench/api/node/extHostDecorations';
import { toGlobPattern, toLanguageSelector } from 'vs/workbench/api/node/extHostTypeConverters';
import { ExtensionActivatedByAPI } from 'vs/workbench/api/node/extHostExtensionActivator';
import { ILogService } from 'vs/platform/log/common/log';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
export interface IExtensionApiFactory {
......@@ -82,8 +81,7 @@ export function createApiFactory(
threadService: ExtHostThreadService,
extHostWorkspace: ExtHostWorkspace,
extHostConfiguration: ExtHostConfiguration,
extensionService: ExtHostExtensionService,
logService: ILogService
extensionService: ExtHostExtensionService
): IExtensionApiFactory {
// Addressable instances
......@@ -94,7 +92,7 @@ export function createApiFactory(
const extHostDocumentContentProviders = threadService.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(threadService, extHostDocumentsAndEditors));
const extHostDocumentSaveParticipant = threadService.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadEditors)));
const extHostEditors = threadService.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(threadService, extHostDocumentsAndEditors));
const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService, logService));
const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService));
const extHostTreeViews = threadService.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(threadService.get(MainContext.MainThreadTreeViews), extHostCommands));
threadService.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
const extHostDebugService = threadService.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(threadService, extHostWorkspace));
......@@ -105,7 +103,7 @@ export function createApiFactory(
const extHostFileSystemEvent = threadService.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService());
const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService, extHostWorkspace, extHostCommands));
const extHostTerminalService = threadService.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(threadService));
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands, logService));
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands));
const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService, extHostWorkspace));
const extHostWindow = threadService.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(threadService));
threadService.set(ExtHostContext.ExtHostExtensionService, extensionService);
......
......@@ -15,7 +15,7 @@ import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import * as modes from 'vs/editor/common/modes';
import * as vscode from 'vscode';
import { ILogService, log, LogLevel } from 'vs/platform/log/common/log';
import { log, LogLevel } from 'vs/platform/log/common/log';
interface CommandHandler {
callback: Function;
......@@ -36,9 +36,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
constructor(
mainContext: IMainContext,
heapService: ExtHostHeapService,
// @ts-ignore
@ILogService private logService: ILogService
heapService: ExtHostHeapService
) {
this._proxy = mainContext.get(MainContext.MainThreadCommands);
this._converter = new CommandsConverter(this, heapService);
......
......@@ -21,7 +21,6 @@ import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { realpath } from 'fs';
import { TernarySearchTree } from 'vs/base/common/map';
import { Barrier } from 'vs/base/common/async';
import { ILogService } from 'vs/platform/log/common/log';
class ExtensionMemento implements IExtensionMemento {
......@@ -126,8 +125,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
constructor(initData: IInitData,
threadService: ExtHostThreadService,
extHostWorkspace: ExtHostWorkspace,
extHostConfiguration: ExtHostConfiguration,
logService: ILogService
extHostConfiguration: ExtHostConfiguration
) {
this._barrier = new Barrier();
this._registry = new ExtensionDescriptionRegistry(initData.extensions);
......@@ -139,7 +137,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
this._activator = null;
// initialize API first (i.e. do not release barrier until the API is initialized)
const apiFactory = createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, this, logService);
const apiFactory = createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, this);
initializeExtensionApi(this, apiFactory).then(() => {
......
......@@ -17,7 +17,7 @@ import { sortedDiff } from 'vs/base/common/arrays';
import { comparePaths } from 'vs/base/common/comparers';
import * as vscode from 'vscode';
import { ISplice } from 'vs/base/common/sequence';
import { log, LogLevel, ILogService } from 'vs/platform/log/common/log';
import { log, LogLevel } from 'vs/platform/log/common/log';
type ProviderHandle = number;
type GroupHandle = number;
......@@ -444,9 +444,7 @@ export class ExtHostSCM {
constructor(
mainContext: IMainContext,
private _commands: ExtHostCommands,
// @ts-ignore
@ILogService private logService: ILogService
private _commands: ExtHostCommands
) {
this._proxy = mainContext.get(MainContext.MainThreadSCM);
......
......@@ -42,6 +42,7 @@ import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import fs = require('fs');
import { registerGlobalLogService } from 'vs/platform/log/common/log';
gracefulFs.gracefulify(fs); // enable gracefulFs
const currentWindowId = remote.getCurrentWindow().id;
......@@ -74,6 +75,8 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
const environmentService = new EnvironmentService(configuration, configuration.execPath);
const logService = new SpdLogService(`renderer${currentWindowId}`, environmentService);
registerGlobalLogService(logService);
logService.info('openWorkbench', JSON.stringify(configuration));
// Since the configuration service is one of the core services that is used in so many places, we initialize it
......
......@@ -24,6 +24,7 @@ import * as glob from 'vs/base/common/glob';
import { ExtensionActivatedByEvent } from 'vs/workbench/api/node/extHostExtensionActivator';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import { registerGlobalLogService } from 'vs/platform/log/common/log';
// const nativeExit = process.exit.bind(process);
function patchProcess(allowExit: boolean) {
......@@ -88,10 +89,12 @@ export class ExtensionHostMain {
const extHostWorkspace = new ExtHostWorkspace(threadService, initData.workspace);
const environmentService = new EnvironmentService(initData.args, initData.execPath);
const logService = new SpdLogService(`exthost${initData.windowId}`, environmentService);
registerGlobalLogService(logService);
logService.info('main {0}', initData);
this._extHostConfiguration = new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration);
this._extensionService = new ExtHostExtensionService(initData, threadService, extHostWorkspace, this._extHostConfiguration, logService);
this._extensionService = new ExtHostExtensionService(initData, threadService, extHostWorkspace, this._extHostConfiguration);
// error forwarding and stack trace scanning
const extensionErrors = new WeakMap<Error, IExtensionDescription>();
......
......@@ -8,7 +8,7 @@
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event';
import { ISCMService, ISCMProvider, ISCMInput, ISCMRepository } from './scm';
import { log, LogLevel, ILogService } from 'vs/platform/log/common/log';
import { log, LogLevel } from 'vs/platform/log/common/log';
class SCMInput implements ISCMInput {
......@@ -77,11 +77,6 @@ export class SCMService implements ISCMService {
private _onDidRemoveProvider = new Emitter<ISCMRepository>();
get onDidRemoveRepository(): Event<ISCMRepository> { return this._onDidRemoveProvider.event; }
constructor(
// @ts-ignore
@ILogService private logService: ILogService
) { }
@log(LogLevel.INFO, 'SCMService')
registerSCMProvider(provider: ISCMProvider): ISCMRepository {
if (this._providerIds.has(provider.id)) {
......
......@@ -32,7 +32,6 @@ import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
import * as vscode from 'vscode';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import 'vs/workbench/parts/search/electron-browser/search.contribution';
import { NoopLogService } from 'vs/platform/log/common/log';
const defaultSelector = { scheme: 'far' };
const model: EditorCommon.IModel = EditorModel.createFromString(
......@@ -113,9 +112,8 @@ suite('ExtHostLanguageFeatureCommands', function () {
threadService.set(ExtHostContext.ExtHostDocuments, extHostDocuments);
const heapService = new ExtHostHeapService();
const logService = new NoopLogService();
commands = new ExtHostCommands(threadService, heapService, logService);
commands = new ExtHostCommands(threadService, heapService);
threadService.set(ExtHostContext.ExtHostCommands, commands);
threadService.setTestInstance(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, threadService));
ExtHostApiCommands.register(commands);
......
......@@ -12,7 +12,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { OneGetThreadService } from './testThreadService';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
import { NoopLogService } from 'vs/platform/log/common/log';
suite('ExtHostCommands', function () {
......@@ -30,7 +29,7 @@ suite('ExtHostCommands', function () {
}
};
const commands = new ExtHostCommands(OneGetThreadService(shape), undefined, new NoopLogService());
const commands = new ExtHostCommands(OneGetThreadService(shape), undefined);
commands.registerCommand('foo', (): any => { }).dispose();
assert.equal(lastUnregister, 'foo');
assert.equal(CommandsRegistry.getCommand('foo'), undefined);
......@@ -51,7 +50,7 @@ suite('ExtHostCommands', function () {
}
};
const commands = new ExtHostCommands(OneGetThreadService(shape), undefined, new NoopLogService());
const commands = new ExtHostCommands(OneGetThreadService(shape), undefined);
const reg = commands.registerCommand('foo', (): any => { });
reg.dispose();
reg.dispose();
......
......@@ -44,7 +44,6 @@ import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
import * as vscode from 'vscode';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { NoopLogService } from 'vs/platform/log/common/log';
const defaultSelector = { scheme: 'far' };
const model: EditorCommon.IModel = EditorModel.createFromString(
......@@ -103,7 +102,7 @@ suite('ExtHostLanguageFeatures', function () {
const heapService = new ExtHostHeapService();
const commands = new ExtHostCommands(threadService, heapService, new NoopLogService());
const commands = new ExtHostCommands(threadService, heapService);
threadService.set(ExtHostContext.ExtHostCommands, commands);
threadService.setTestInstance(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, threadService));
......
......@@ -17,7 +17,6 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/
import { MainThreadCommands } from 'vs/workbench/api/electron-browser/mainThreadCommands';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
import { NoopLogService } from 'vs/platform/log/common/log';
import { TPromise } from 'vs/base/common/winjs.base';
import { TreeItemCollapsibleState, ITreeItem } from 'vs/workbench/common/views';
......@@ -66,7 +65,7 @@ suite('ExtHostTreeView', function () {
threadService.setTestInstance(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, threadService));
target = new RecordingShape();
testObject = new ExtHostTreeViews(target, new ExtHostCommands(threadService, new ExtHostHeapService(), new NoopLogService()));
testObject = new ExtHostTreeViews(target, new ExtHostCommands(threadService, new ExtHostHeapService()));
onDidChangeTreeData = new Emitter<string>();
testObject.registerTreeDataProvider('testDataProvider', aTreeDataProvider());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册