Skip to content

Commit 2b5d14e

Browse files
committed
drop global log service
1 parent d21eb1a commit 2b5d14e

6 files changed

Lines changed: 44 additions & 38 deletions

File tree

src/vs/platform/commands/common/commandService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
1111
import Event, { Emitter } from 'vs/base/common/event';
1212
import { Disposable } from 'vs/base/common/lifecycle';
1313
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
14-
import { log, LogLevel } from 'vs/platform/log/common/log';
14+
import { log, LogLevel, ILogService } from 'vs/platform/log/common/log';
1515

1616
export class CommandService extends Disposable implements ICommandService {
1717

@@ -25,7 +25,9 @@ export class CommandService extends Disposable implements ICommandService {
2525
constructor(
2626
@IInstantiationService private _instantiationService: IInstantiationService,
2727
@IExtensionService private _extensionService: IExtensionService,
28-
@IContextKeyService private _contextKeyService: IContextKeyService
28+
@IContextKeyService private _contextKeyService: IContextKeyService,
29+
// @ts-ignore
30+
@ILogService private logService: ILogService
2931
) {
3032
super();
3133
this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value);

src/vs/platform/commands/test/commandService.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyServ
1616
import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices';
1717
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1818
import Event, { Emitter } from 'vs/base/common/event';
19+
import { ILogService } from 'vs/platform/log/common/log';
20+
21+
class NoopLogService implements ILogService {
22+
_serviceBrand: any;
23+
trace(message: string, ...args: any[]): void { }
24+
debug(message: string, ...args: any[]): void { }
25+
info(message: string, ...args: any[]): void { }
26+
warn(message: string, ...args: any[]): void { }
27+
error(message: string | Error, ...args: any[]): void { }
28+
critical(message: string | Error, ...args: any[]): void { }
29+
}
1930

2031
class SimpleExtensionService implements IExtensionService {
2132
_serviceBrand: any;
@@ -70,7 +81,7 @@ suite('CommandService', function () {
7081
lastEvent = activationEvent;
7182
return super.activateByEvent(activationEvent);
7283
}
73-
}, new ContextKeyService(new SimpleConfigurationService()));
84+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
7485

7586
return service.executeCommand('foo').then(() => {
7687
assert.ok(lastEvent, 'onCommand:foo');
@@ -88,7 +99,7 @@ suite('CommandService', function () {
8899
activateByEvent(activationEvent: string): TPromise<void> {
89100
return TPromise.wrapError<void>(new Error('bad_activate'));
90101
}
91-
}, new ContextKeyService(new SimpleConfigurationService()));
102+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
92103

93104
return service.executeCommand('foo').then(() => assert.ok(false), err => {
94105
assert.equal(err.message, 'bad_activate');
@@ -104,7 +115,7 @@ suite('CommandService', function () {
104115
whenInstalledExtensionsRegistered() {
105116
return new TPromise<boolean>(_resolve => { /*ignore*/ });
106117
}
107-
}, new ContextKeyService(new SimpleConfigurationService()));
118+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
108119

109120
service.executeCommand('bar');
110121
assert.equal(callCounter, 1);
@@ -121,7 +132,7 @@ suite('CommandService', function () {
121132
whenInstalledExtensionsRegistered() {
122133
return new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
123134
}
124-
}, new ContextKeyService(new SimpleConfigurationService()));
135+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
125136

126137
let r = service.executeCommand('bar');
127138
assert.equal(callCounter, 0);
@@ -140,7 +151,8 @@ suite('CommandService', function () {
140151
let commandService = new CommandService(
141152
new InstantiationService(),
142153
new SimpleExtensionService(),
143-
contextKeyService
154+
contextKeyService,
155+
new NoopLogService()
144156
);
145157

146158
let counter = 0;

src/vs/platform/log/common/log.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,22 @@ export class LegacyLogMainService implements ILogService {
6767
}
6868
}
6969

70-
export let globalLogService: ILogService | undefined;
71-
72-
export function setGlobalLogService(logService: ILogService): void {
73-
globalLogService = logService;
74-
}
75-
76-
export function log(level: LogLevel, prefix: string, fn?: (...args: any[]) => string): Function {
70+
export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function {
7771
return createDecorator((fn, key) => {
7872
return function (this: any, ...args: any[]) {
7973
let message = `${prefix} - ${key}`;
8074

81-
if (fn) {
82-
message = fn(message, ...args);
75+
if (logFn) {
76+
message = logFn(message, ...args);
8377
}
8478

8579
switch (level) {
86-
case LogLevel.TRACE: globalLogService.trace(message);
87-
case LogLevel.DEBUG: globalLogService.debug(message);
88-
case LogLevel.INFO: globalLogService.info(message);
89-
case LogLevel.WARN: globalLogService.warn(message);
90-
case LogLevel.ERROR: globalLogService.error(message);
91-
case LogLevel.CRITICAL: globalLogService.critical(message);
80+
case LogLevel.TRACE: this.logService.trace(message); break;
81+
case LogLevel.DEBUG: this.logService.debug(message); break;
82+
case LogLevel.INFO: this.logService.info(message); break;
83+
case LogLevel.WARN: this.logService.warn(message); break;
84+
case LogLevel.ERROR: this.logService.error(message); break;
85+
case LogLevel.CRITICAL: this.logService.critical(message); break;
9286
}
9387

9488
return fn.apply(this, args);

src/vs/platform/log/node/spdlogService.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
import { ILogService, setGlobalLogService } from 'vs/platform/log/common/log';
8+
import { ILogService } from 'vs/platform/log/common/log';
99
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1010

1111
export class SpdLogService implements ILogService {
@@ -14,37 +14,32 @@ export class SpdLogService implements ILogService {
1414

1515
constructor(
1616
processName: string,
17-
setGlobal: boolean,
1817
@IEnvironmentService environmentService: IEnvironmentService
1918
) {
2019
// TODO create logger
21-
22-
if (setGlobal) {
23-
setGlobalLogService(this);
24-
}
2520
}
2621

2722
trace(message: string, ...args: any[]): void {
28-
// throw new Error('Method not implemented.');
23+
console.log('TRACE', message, ...args);
2924
}
3025

3126
debug(message: string, ...args: any[]): void {
32-
// throw new Error('Method not implemented.');
27+
console.log('DEBUG', message, ...args);
3328
}
3429

3530
info(message: string, ...args: any[]): void {
36-
// throw new Error('Method not implemented.');
31+
console.log('INFO', message, ...args);
3732
}
3833

3934
warn(message: string, ...args: any[]): void {
40-
// throw new Error('Method not implemented.');
35+
console.warn('WARN', message, ...args);
4136
}
4237

4338
error(message: string | Error, ...args: any[]): void {
44-
// throw new Error('Method not implemented.');
39+
console.error('ERROR', message, ...args);
4540
}
4641

4742
critical(message: string, ...args: any[]): void {
48-
// throw new Error('Method not implemented.');
43+
console.error('CRITICAL', message, ...args);
4944
}
5045
}

src/vs/workbench/electron-browser/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
7373
const mainServices = createMainProcessServices(mainProcessClient);
7474

7575
const environmentService = new EnvironmentService(configuration, configuration.execPath);
76-
const logService = new SpdLogService('renderer', true, environmentService);
77-
logService.info('openWorkbench', JSON.stringify(configuration, null, 2));
76+
const logService = new SpdLogService('renderer', environmentService);
77+
logService.info('openWorkbench', JSON.stringify(configuration));
7878

7979
// Since the configuration service is one of the core services that is used in so many places, we initialize it
8080
// right before startup of the workbench shell to have its data ready for consumers

src/vs/workbench/services/scm/common/scmService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
99
import Event, { Emitter } from 'vs/base/common/event';
1010
import { ISCMService, ISCMProvider, ISCMInput, ISCMRepository } from './scm';
11-
import { log, LogLevel } from 'vs/platform/log/common/log';
11+
import { log, LogLevel, ILogService } from 'vs/platform/log/common/log';
1212

1313
class SCMInput implements ISCMInput {
1414

@@ -77,7 +77,10 @@ export class SCMService implements ISCMService {
7777
private _onDidRemoveProvider = new Emitter<ISCMRepository>();
7878
get onDidRemoveRepository(): Event<ISCMRepository> { return this._onDidRemoveProvider.event; }
7979

80-
constructor() { }
80+
constructor(
81+
// @ts-ignore
82+
@ILogService private logService: ILogService
83+
) { }
8184

8285
@log(LogLevel.INFO, 'SCMService')
8386
registerSCMProvider(provider: ISCMProvider): ISCMRepository {

0 commit comments

Comments
 (0)