提交 2b5d14e4 编写于 作者: J Joao Moreno

drop global log service

上级 d21eb1ad
......@@ -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);
......
......@@ -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<void> {
return TPromise.wrapError<void>(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<boolean>(_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<boolean>(_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;
......
......@@ -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);
......
......@@ -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
......@@ -73,8 +73,8 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
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
......
......@@ -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<ISCMRepository>();
get onDidRemoveRepository(): Event<ISCMRepository> { return this._onDidRemoveProvider.event; }
constructor() { }
constructor(
// @ts-ignore
@ILogService private logService: ILogService
) { }
@log(LogLevel.INFO, 'SCMService')
registerSCMProvider(provider: ISCMProvider): ISCMRepository {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册