Skip to content

Commit

Permalink
#39574 Define interface ILogLevelSetter
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jan 23, 2018
1 parent 7155f39 commit f2b303f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { createSharedProcessContributions } from 'vs/code/electron-browser/sharedProcess/contrib/contributions';
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
import { ILogService, FollowerLogService } from 'vs/platform/log/common/log';
import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc';
import { LogLevelSetterChannelClient } from 'vs/platform/log/common/logIpc';

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { DarwinUpdateService } from 'vs/platform/update/electron-main/updateServ
import { IIssueService } from 'vs/platform/issue/common/issue';
import { IssueChannel } from 'vs/platform/issue/common/issueIpc';
import { IssueService } from 'vs/platform/issue/electron-main/issueService';
import { LogLevelChannel } from 'vs/platform/log/common/logIpc';
import { LogLevelSetterChannel } from 'vs/platform/log/common/logIpc';

export class CodeApplication {

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

// Log level management
const logLevelChannel = new LogLevelChannel(accessor.get(ILogService));
const logLevelChannel = new LogLevelSetterChannel(accessor.get(ILogService));
this.electronIpcServer.registerChannel('loglevel', logLevelChannel);
this.sharedProcessClient.done(client => client.registerChannel('loglevel', logLevelChannel));

Expand Down
26 changes: 18 additions & 8 deletions src/vs/platform/log/common/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { createDecorator as createServiceDecorator } from 'vs/platform/instantia
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { isWindows } from 'vs/base/common/platform';
import Event, { Emitter } from 'vs/base/common/event';
import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc';

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

Expand All @@ -24,11 +23,14 @@ export enum LogLevel {
Off
}

export interface ILogService extends IDisposable {
_serviceBrand: any;

export interface ILogLevelSetter {
onDidChangeLogLevel: Event<LogLevel>;
setLevel(level: LogLevel): void;
}

export interface ILogService extends ILogLevelSetter, IDisposable {
_serviceBrand: any;

getLevel(): LogLevel;
trace(message: string, ...args: any[]): void;
debug(message: string, ...args: any[]): void;
Expand Down Expand Up @@ -237,16 +239,24 @@ export class MultiplexLogService extends AbstractLogService implements ILogServi
}
}

export class FollowerLogService extends AbstractLogService implements ILogService {
export class FollowerLogService extends Disposable implements ILogService {
_serviceBrand: any;

constructor(private client: LogLevelChannelClient, private logService: ILogService) {
constructor(private master: ILogLevelSetter, private logService: ILogService) {
super();
this._register(client.onDidChangeLogLevel(level => logService.setLevel(level)));
this._register(master.onDidChangeLogLevel(level => logService.setLevel(level)));
}

get onDidChangeLogLevel(): Event<LogLevel> {
return this.logService.onDidChangeLogLevel;
}

setLevel(level: LogLevel): void {
this.client.setLogLevel(level);
this.master.setLevel(level);
}

getLevel(): LogLevel {
return this.logService.getLevel();
}

trace(message: string, ...args: any[]): void {
Expand Down
18 changes: 9 additions & 9 deletions src/vs/platform/log/common/logIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
import { TPromise } from 'vs/base/common/winjs.base';
import { LogLevel, ILogService } from 'vs/platform/log/common/log';
import { LogLevel, ILogService, ILogLevelSetter } from 'vs/platform/log/common/log';
import Event, { buffer } from 'vs/base/common/event';

export interface ILogLevelManagementChannel extends IChannel {
export interface ILogLevelSetterChannel extends IChannel {
call(command: 'event:onDidChangeLogLevel'): TPromise<LogLevel>;
call(command: 'setLogLevel', logLevel: LogLevel): TPromise<void>;
call(command: 'setLevel', logLevel: LogLevel): TPromise<void>;
}

export class LogLevelChannel implements ILogLevelManagementChannel {
export class LogLevelSetterChannel implements ILogLevelSetterChannel {

onDidChangeLogLevel: Event<LogLevel>;

Expand All @@ -24,20 +24,20 @@ export class LogLevelChannel implements ILogLevelManagementChannel {
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'event:onDidChangeLogLevel': return eventToCall(this.onDidChangeLogLevel);
case 'setLogLevel': this.service.setLevel(arg); return TPromise.as(null);
case 'setLevel': this.service.setLevel(arg); return TPromise.as(null);
}
return undefined;
}
}

export class LogLevelChannelClient {
export class LogLevelSetterChannelClient implements ILogLevelSetter {

constructor(private channel: ILogLevelManagementChannel) { }
constructor(private channel: ILogLevelSetterChannel) { }

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

setLogLevel(level: LogLevel): TPromise<void> {
return this.channel.call('setLogLevel', level);
setLevel(level: LogLevel): TPromise<void> {
return this.channel.call('setLevel', level);
}
}
4 changes: 2 additions & 2 deletions src/vs/workbench/electron-browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import fs = require('fs');
import { ConsoleLogService, MultiplexLogService, ILogService, FollowerLogService } from 'vs/platform/log/common/log';
import { IssueChannelClient } from 'vs/platform/issue/common/issueIpc';
import { IIssueService } from 'vs/platform/issue/common/issue';
import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc';
import { LogLevelSetterChannelClient } from 'vs/platform/log/common/logIpc';
gracefulFs.gracefulify(fs); // enable gracefulFs

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

Expand Down

0 comments on commit f2b303f

Please sign in to comment.