提交 d21eb1ad 编写于 作者: J Joao Moreno

log decorator

上级 4cc2dfea
......@@ -11,6 +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';
export class CommandService extends Disposable implements ICommandService {
......@@ -30,6 +31,7 @@ export class CommandService extends Disposable implements ICommandService {
this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value);
}
@log(LogLevel.INFO, 'CommandService', (msg, id) => `${msg}(${id})`)
executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
// we always send an activation event, but
// we don't wait for it when the extension
......
......@@ -5,10 +5,20 @@
'use strict';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { createDecorator as createServiceDecorator } from 'vs/platform/instantiation/common/instantiation';
import { createDecorator } from 'vs/base/common/decorators';
export const ILogService = createDecorator<ILogService>('logService');
export const ILogService = createServiceDecorator<ILogService>('logService');
export enum LogLevel {
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
CRITICAL
}
export interface ILogService {
_serviceBrand: any;
......@@ -55,4 +65,33 @@ export class LegacyLogMainService implements ILogService {
critical(message: string, ...args: any[]): void {
// console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, ...args);
}
}
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 {
return createDecorator((fn, key) => {
return function (this: any, ...args: any[]) {
let message = `${prefix} - ${key}`;
if (fn) {
message = fn(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);
}
return fn.apply(this, args);
};
});
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
'use strict';
import { ILogService } from 'vs/platform/log/common/log';
import { ILogService, setGlobalLogService } from 'vs/platform/log/common/log';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
export class SpdLogService implements ILogService {
......@@ -14,9 +14,14 @@ 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 {
......
......@@ -73,7 +73,7 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
const mainServices = createMainProcessServices(mainProcessClient);
const environmentService = new EnvironmentService(configuration, configuration.execPath);
const logService = new SpdLogService('renderer', environmentService);
const logService = new SpdLogService('renderer', true, environmentService);
logService.info('openWorkbench', JSON.stringify(configuration, null, 2));
// Since the configuration service is one of the core services that is used in so many places, we initialize it
......
......@@ -8,6 +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';
class SCMInput implements ISCMInput {
......@@ -78,6 +79,7 @@ export class SCMService implements ISCMService {
constructor() { }
@log(LogLevel.INFO, 'SCMService')
registerSCMProvider(provider: ISCMProvider): ISCMRepository {
if (this._providerIds.has(provider.id)) {
throw new Error(`SCM Provider ${provider.id} already exists.`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册