Skip to content

Commit f2b303f

Browse files
committed
microsoft#39574 Define interface ILogLevelSetter
1 parent 7155f39 commit f2b303f

5 files changed

Lines changed: 33 additions & 23 deletions

File tree

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
3939
import { createSharedProcessContributions } from 'vs/code/electron-browser/sharedProcess/contrib/contributions';
4040
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
4141
import { ILogService, FollowerLogService } from 'vs/platform/log/common/log';
42-
import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc';
42+
import { LogLevelSetterChannelClient } from 'vs/platform/log/common/logIpc';
4343

4444
export interface ISharedProcessConfiguration {
4545
readonly machineId: string;
@@ -82,7 +82,7 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
8282
const services = new ServiceCollection();
8383

8484
const environmentService = new EnvironmentService(initData.args, process.execPath);
85-
const logLevelClient = new LogLevelChannelClient(server.getChannel('loglevel', { route: () => 'main' }));
85+
const logLevelClient = new LogLevelSetterChannelClient(server.getChannel('loglevel', { route: () => 'main' }));
8686
const logService = new FollowerLogService(logLevelClient, createSpdLogService('sharedprocess', environmentService));
8787
process.once('exit', () => logService.dispose());
8888

src/vs/code/electron-main/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import { DarwinUpdateService } from 'vs/platform/update/electron-main/updateServ
5757
import { IIssueService } from 'vs/platform/issue/common/issue';
5858
import { IssueChannel } from 'vs/platform/issue/common/issueIpc';
5959
import { IssueService } from 'vs/platform/issue/electron-main/issueService';
60-
import { LogLevelChannel } from 'vs/platform/log/common/logIpc';
60+
import { LogLevelSetterChannel } from 'vs/platform/log/common/logIpc';
6161

6262
export class CodeApplication {
6363

@@ -380,7 +380,7 @@ export class CodeApplication {
380380
this.sharedProcessClient.done(client => client.registerChannel('windows', windowsChannel));
381381

382382
// Log level management
383-
const logLevelChannel = new LogLevelChannel(accessor.get(ILogService));
383+
const logLevelChannel = new LogLevelSetterChannel(accessor.get(ILogService));
384384
this.electronIpcServer.registerChannel('loglevel', logLevelChannel);
385385
this.sharedProcessClient.done(client => client.registerChannel('loglevel', logLevelChannel));
386386

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { createDecorator as createServiceDecorator } from 'vs/platform/instantia
1010
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
1111
import { isWindows } from 'vs/base/common/platform';
1212
import Event, { Emitter } from 'vs/base/common/event';
13-
import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc';
1413

1514
export const ILogService = createServiceDecorator<ILogService>('logService');
1615

@@ -24,11 +23,14 @@ export enum LogLevel {
2423
Off
2524
}
2625

27-
export interface ILogService extends IDisposable {
28-
_serviceBrand: any;
29-
26+
export interface ILogLevelSetter {
3027
onDidChangeLogLevel: Event<LogLevel>;
3128
setLevel(level: LogLevel): void;
29+
}
30+
31+
export interface ILogService extends ILogLevelSetter, IDisposable {
32+
_serviceBrand: any;
33+
3234
getLevel(): LogLevel;
3335
trace(message: string, ...args: any[]): void;
3436
debug(message: string, ...args: any[]): void;
@@ -237,16 +239,24 @@ export class MultiplexLogService extends AbstractLogService implements ILogServi
237239
}
238240
}
239241

240-
export class FollowerLogService extends AbstractLogService implements ILogService {
242+
export class FollowerLogService extends Disposable implements ILogService {
241243
_serviceBrand: any;
242244

243-
constructor(private client: LogLevelChannelClient, private logService: ILogService) {
245+
constructor(private master: ILogLevelSetter, private logService: ILogService) {
244246
super();
245-
this._register(client.onDidChangeLogLevel(level => logService.setLevel(level)));
247+
this._register(master.onDidChangeLogLevel(level => logService.setLevel(level)));
248+
}
249+
250+
get onDidChangeLogLevel(): Event<LogLevel> {
251+
return this.logService.onDidChangeLogLevel;
246252
}
247253

248254
setLevel(level: LogLevel): void {
249-
this.client.setLogLevel(level);
255+
this.master.setLevel(level);
256+
}
257+
258+
getLevel(): LogLevel {
259+
return this.logService.getLevel();
250260
}
251261

252262
trace(message: string, ...args: any[]): void {

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

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

66
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
77
import { TPromise } from 'vs/base/common/winjs.base';
8-
import { LogLevel, ILogService } from 'vs/platform/log/common/log';
8+
import { LogLevel, ILogService, ILogLevelSetter } from 'vs/platform/log/common/log';
99
import Event, { buffer } from 'vs/base/common/event';
1010

11-
export interface ILogLevelManagementChannel extends IChannel {
11+
export interface ILogLevelSetterChannel extends IChannel {
1212
call(command: 'event:onDidChangeLogLevel'): TPromise<LogLevel>;
13-
call(command: 'setLogLevel', logLevel: LogLevel): TPromise<void>;
13+
call(command: 'setLevel', logLevel: LogLevel): TPromise<void>;
1414
}
1515

16-
export class LogLevelChannel implements ILogLevelManagementChannel {
16+
export class LogLevelSetterChannel implements ILogLevelSetterChannel {
1717

1818
onDidChangeLogLevel: Event<LogLevel>;
1919

@@ -24,20 +24,20 @@ export class LogLevelChannel implements ILogLevelManagementChannel {
2424
call(command: string, arg?: any): TPromise<any> {
2525
switch (command) {
2626
case 'event:onDidChangeLogLevel': return eventToCall(this.onDidChangeLogLevel);
27-
case 'setLogLevel': this.service.setLevel(arg); return TPromise.as(null);
27+
case 'setLevel': this.service.setLevel(arg); return TPromise.as(null);
2828
}
2929
return undefined;
3030
}
3131
}
3232

33-
export class LogLevelChannelClient {
33+
export class LogLevelSetterChannelClient implements ILogLevelSetter {
3434

35-
constructor(private channel: ILogLevelManagementChannel) { }
35+
constructor(private channel: ILogLevelSetterChannel) { }
3636

3737
private _onDidChangeLogLevel = eventFromCall<LogLevel>(this.channel, 'event:onDidChangeLogLevel');
3838
get onDidChangeLogLevel(): Event<LogLevel> { return this._onDidChangeLogLevel; }
3939

40-
setLogLevel(level: LogLevel): TPromise<void> {
41-
return this.channel.call('setLogLevel', level);
40+
setLevel(level: LogLevel): TPromise<void> {
41+
return this.channel.call('setLevel', level);
4242
}
4343
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import fs = require('fs');
4646
import { ConsoleLogService, MultiplexLogService, ILogService, FollowerLogService } from 'vs/platform/log/common/log';
4747
import { IssueChannelClient } from 'vs/platform/issue/common/issueIpc';
4848
import { IIssueService } from 'vs/platform/issue/common/issue';
49-
import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc';
49+
import { LogLevelSetterChannelClient } from 'vs/platform/log/common/logIpc';
5050
gracefulFs.gracefulify(fs); // enable gracefulFs
5151

5252
export function startup(configuration: IWindowConfiguration): TPromise<void> {
@@ -202,7 +202,7 @@ function createLogService(mainProcessClient: ElectronIPCClient, configuration: I
202202
const spdlogService = createSpdLogService(`renderer${configuration.windowId}`, environmentService);
203203
const consoleLogService = new ConsoleLogService(environmentService);
204204
const logService = new MultiplexLogService([consoleLogService, spdlogService]);
205-
const logLevelClient = new LogLevelChannelClient(mainProcessClient.getChannel('loglevel'));
205+
const logLevelClient = new LogLevelSetterChannelClient(mainProcessClient.getChannel('loglevel'));
206206
return new FollowerLogService(logLevelClient, logService);
207207
}
208208

0 commit comments

Comments
 (0)