diff --git a/src/vs/platform/commands/common/commandService.ts b/src/vs/platform/commands/common/commandService.ts index ab1c14271a75080c30f771453c42b9c7f2bae50d..a8fc43ad4da3c3002898ca5b24c049329412e53c 100644 --- a/src/vs/platform/commands/common/commandService.ts +++ b/src/vs/platform/commands/common/commandService.ts @@ -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 } from 'vs/platform/log/common/log'; +import { log, LogLevel, ILogService } from 'vs/platform/log/common/log'; export class CommandService extends Disposable implements ICommandService { @@ -25,7 +25,9 @@ export class CommandService extends Disposable implements ICommandService { constructor( @IInstantiationService private _instantiationService: IInstantiationService, @IExtensionService private _extensionService: IExtensionService, - @IContextKeyService private _contextKeyService: IContextKeyService + @IContextKeyService private _contextKeyService: IContextKeyService, + // @ts-ignore + @ILogService private logService: ILogService ) { super(); this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value); diff --git a/src/vs/platform/commands/test/commandService.test.ts b/src/vs/platform/commands/test/commandService.test.ts index 4d262f8b2d829a9d37499608e9aec7e7b89b910d..f5f927255d58a8b1e01800ae877a762eb9ef5aa9 100644 --- a/src/vs/platform/commands/test/commandService.test.ts +++ b/src/vs/platform/commands/test/commandService.test.ts @@ -16,6 +16,17 @@ 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 { ILogService } from 'vs/platform/log/common/log'; + +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 { } +} class SimpleExtensionService implements IExtensionService { _serviceBrand: any; @@ -70,7 +81,7 @@ suite('CommandService', function () { lastEvent = activationEvent; return super.activateByEvent(activationEvent); } - }, new ContextKeyService(new SimpleConfigurationService())); + }, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService()); return service.executeCommand('foo').then(() => { assert.ok(lastEvent, 'onCommand:foo'); @@ -88,7 +99,7 @@ suite('CommandService', function () { activateByEvent(activationEvent: string): TPromise { return TPromise.wrapError(new Error('bad_activate')); } - }, new ContextKeyService(new SimpleConfigurationService())); + }, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService()); return service.executeCommand('foo').then(() => assert.ok(false), err => { assert.equal(err.message, 'bad_activate'); @@ -104,7 +115,7 @@ suite('CommandService', function () { whenInstalledExtensionsRegistered() { return new TPromise(_resolve => { /*ignore*/ }); } - }, new ContextKeyService(new SimpleConfigurationService())); + }, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService()); service.executeCommand('bar'); assert.equal(callCounter, 1); @@ -121,7 +132,7 @@ suite('CommandService', function () { whenInstalledExtensionsRegistered() { return new TPromise(_resolve => { resolveFunc = _resolve; }); } - }, new ContextKeyService(new SimpleConfigurationService())); + }, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService()); let r = service.executeCommand('bar'); assert.equal(callCounter, 0); @@ -140,7 +151,8 @@ suite('CommandService', function () { let commandService = new CommandService( new InstantiationService(), new SimpleExtensionService(), - contextKeyService + contextKeyService, + new NoopLogService() ); let counter = 0; diff --git a/src/vs/platform/log/common/log.ts b/src/vs/platform/log/common/log.ts index c52962e86e63f69df106fa194455b9d504ef416f..0312a8e7c54cf4f9d21c2bb2015169f16d186d43 100644 --- a/src/vs/platform/log/common/log.ts +++ b/src/vs/platform/log/common/log.ts @@ -67,28 +67,22 @@ export class LegacyLogMainService implements ILogService { } } -export let globalLogService: ILogService | undefined; - -export function setGlobalLogService(logService: ILogService): void { - globalLogService = logService; -} - -export function log(level: LogLevel, prefix: string, fn?: (...args: any[]) => string): Function { +export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function { return createDecorator((fn, key) => { return function (this: any, ...args: any[]) { let message = `${prefix} - ${key}`; - if (fn) { - message = fn(message, ...args); + if (logFn) { + message = logFn(message, ...args); } switch (level) { - case LogLevel.TRACE: globalLogService.trace(message); - case LogLevel.DEBUG: globalLogService.debug(message); - case LogLevel.INFO: globalLogService.info(message); - case LogLevel.WARN: globalLogService.warn(message); - case LogLevel.ERROR: globalLogService.error(message); - case LogLevel.CRITICAL: globalLogService.critical(message); + 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; } return fn.apply(this, args); diff --git a/src/vs/platform/log/node/spdlogService.ts b/src/vs/platform/log/node/spdlogService.ts index 6a7fc555b042eea412c7ddb02b0ed956ba986e44..5d4e1a789fa11619ebce66d1807b48e09fa069b5 100644 --- a/src/vs/platform/log/node/spdlogService.ts +++ b/src/vs/platform/log/node/spdlogService.ts @@ -5,7 +5,7 @@ 'use strict'; -import { ILogService, setGlobalLogService } from 'vs/platform/log/common/log'; +import { ILogService } from 'vs/platform/log/common/log'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; export class SpdLogService implements ILogService { @@ -14,37 +14,32 @@ export class SpdLogService implements ILogService { constructor( processName: string, - setGlobal: boolean, @IEnvironmentService environmentService: IEnvironmentService ) { // TODO create logger - - if (setGlobal) { - setGlobalLogService(this); - } } trace(message: string, ...args: any[]): void { - // throw new Error('Method not implemented.'); + console.log('TRACE', message, ...args); } debug(message: string, ...args: any[]): void { - // throw new Error('Method not implemented.'); + console.log('DEBUG', message, ...args); } info(message: string, ...args: any[]): void { - // throw new Error('Method not implemented.'); + console.log('INFO', message, ...args); } warn(message: string, ...args: any[]): void { - // throw new Error('Method not implemented.'); + console.warn('WARN', message, ...args); } error(message: string | Error, ...args: any[]): void { - // throw new Error('Method not implemented.'); + console.error('ERROR', message, ...args); } critical(message: string, ...args: any[]): void { - // throw new Error('Method not implemented.'); + console.error('CRITICAL', message, ...args); } } \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index 6de24e7836551796a3c96881088ec6017b210d3c..047788587f2c302542095da2197b0e9690dea4c6 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -73,8 +73,8 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise { const mainServices = createMainProcessServices(mainProcessClient); const environmentService = new EnvironmentService(configuration, configuration.execPath); - const logService = new SpdLogService('renderer', true, environmentService); - logService.info('openWorkbench', JSON.stringify(configuration, null, 2)); + const logService = new SpdLogService('renderer', environmentService); + 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 // right before startup of the workbench shell to have its data ready for consumers diff --git a/src/vs/workbench/services/scm/common/scmService.ts b/src/vs/workbench/services/scm/common/scmService.ts index e1dbcd99b488ab20e55e3f7f300e664d051e1ae5..614c0a4d664ab58c3e6f237394404197e0b5c8a9 100644 --- a/src/vs/workbench/services/scm/common/scmService.ts +++ b/src/vs/workbench/services/scm/common/scmService.ts @@ -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 } from 'vs/platform/log/common/log'; +import { log, LogLevel, ILogService } from 'vs/platform/log/common/log'; class SCMInput implements ISCMInput { @@ -77,7 +77,10 @@ export class SCMService implements ISCMService { private _onDidRemoveProvider = new Emitter(); get onDidRemoveRepository(): Event { return this._onDidRemoveProvider.event; } - constructor() { } + constructor( + // @ts-ignore + @ILogService private logService: ILogService + ) { } @log(LogLevel.INFO, 'SCMService') registerSCMProvider(provider: ISCMProvider): ISCMRepository {