diff --git a/src/vs/code/electron-browser/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcessMain.ts index 00ef86ffc9c..bd425f7a1f7 100644 --- a/src/vs/code/electron-browser/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcessMain.ts @@ -35,6 +35,8 @@ import { WindowsChannelClient } from 'vs/platform/windows/common/windowsIpc'; import { ipcRenderer } from 'electron'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { createSharedProcessContributions } from 'vs/code/electron-browser/contrib/contributions'; +import { SpdLogService } from 'vs/platform/log/node/spdlogService'; +import { ILogService } from 'vs/platform/log/common/log'; export interface ISharedProcessConfiguration { readonly machineId: string; @@ -76,7 +78,12 @@ const eventPrefix = 'monacoworkbench'; function main(server: Server, initData: ISharedProcessInitData, configuration: ISharedProcessConfiguration): void { const services = new ServiceCollection(); - services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, initData.args, process.execPath)); + const environmentService = new EnvironmentService(initData.args, process.execPath); + const logService = new SpdLogService('sharedprocess', environmentService); + logService.info('main', JSON.stringify(configuration)); + + services.set(IEnvironmentService, environmentService); + services.set(ILogService, logService); services.set(IConfigurationService, new SyncDescriptor(ConfigurationService)); services.set(IRequestService, new SyncDescriptor(RequestService)); diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 15a1cd146c2..7a6d4d8c7c2 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -21,7 +21,7 @@ import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiati import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { ILogService, LegacyLogMainService } from 'vs/platform/log/common/log'; +import { ILogService, LegacyLogMainService, MultiplexLogService } from 'vs/platform/log/common/log'; import { StateService } from 'vs/platform/state/node/stateService'; import { IStateService } from 'vs/platform/state/common/state'; import { IBackupMainService } from 'vs/platform/backup/common/backup'; @@ -46,12 +46,18 @@ import { localize } from 'vs/nls'; import { mnemonicButtonLabel } from 'vs/base/common/labels'; import { listProcesses, ProcessItem } from 'vs/base/node/ps'; import { repeat, pad } from 'vs/base/common/strings'; +import { SpdLogService } from 'vs/platform/log/node/spdlogService'; function createServices(args: ParsedArgs): IInstantiationService { const services = new ServiceCollection(); - services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, args, process.execPath)); - services.set(ILogService, new SyncDescriptor(LegacyLogMainService, 'main')); + const environmentService = new EnvironmentService(args, process.execPath); + const spdlogService = new SpdLogService('main', environmentService); + const legacyLogService = new LegacyLogMainService(environmentService); + const logService = new MultiplexLogService([legacyLogService, spdlogService]); + + services.set(IEnvironmentService, environmentService); + services.set(ILogService, logService); services.set(IWorkspacesMainService, new SyncDescriptor(WorkspacesMainService)); services.set(IHistoryMainService, new SyncDescriptor(HistoryMainService)); services.set(ILifecycleService, new SyncDescriptor(LifecycleService)); diff --git a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts index 6472c256330..046299ca7a1 100644 --- a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts +++ b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts @@ -34,7 +34,7 @@ suite('BackupMainService', () => { class TestBackupMainService extends BackupMainService { constructor(backupHome: string, backupWorkspacesPath: string, configService: TestConfigurationService) { - super(environmentService, configService, new LegacyLogMainService('test', environmentService)); + super(environmentService, configService, new LegacyLogMainService(environmentService)); this.backupHome = backupHome; this.workspacesJsonPath = backupWorkspacesPath; diff --git a/src/vs/platform/log/common/log.ts b/src/vs/platform/log/common/log.ts index 7b12d9563e7..bb487399ecd 100644 --- a/src/vs/platform/log/common/log.ts +++ b/src/vs/platform/log/common/log.ts @@ -35,10 +35,7 @@ export class LegacyLogMainService implements ILogService { _serviceBrand: any; - constructor( - processName: string, - @IEnvironmentService private environmentService: IEnvironmentService - ) { } + constructor( @IEnvironmentService private environmentService: IEnvironmentService) { } trace(message: string, ...args: any[]): void { // console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, ...args); @@ -67,6 +64,48 @@ export class LegacyLogMainService implements ILogService { } } +export class MultiplexLogService implements ILogService { + _serviceBrand: any; + + constructor(private logServices: ILogService[]) { } + + trace(message: string, ...args: any[]): void { + for (const logService of this.logServices) { + logService.trace(message, ...args); + } + } + + debug(message: string, ...args: any[]): void { + for (const logService of this.logServices) { + logService.debug(message, ...args); + } + } + + info(message: string, ...args: any[]): void { + for (const logService of this.logServices) { + logService.info(message, ...args); + } + } + + warn(message: string, ...args: any[]): void { + for (const logService of this.logServices) { + logService.warn(message, ...args); + } + } + + error(message: string | Error, ...args: any[]): void { + for (const logService of this.logServices) { + logService.error(message, ...args); + } + } + + critical(message: string | Error, ...args: any[]): void { + for (const logService of this.logServices) { + logService.critical(message, ...args); + } + } +} + export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function { return createDecorator((fn, key) => { // TODO@Joao: load-time log level? return fn; diff --git a/src/vs/platform/log/node/spdlogService.ts b/src/vs/platform/log/node/spdlogService.ts index a58e5a1ad09..c53896eeaa9 100644 --- a/src/vs/platform/log/node/spdlogService.ts +++ b/src/vs/platform/log/node/spdlogService.ts @@ -22,10 +22,11 @@ export class SpdLogService implements ILogService { ) { setAsyncMode(8192, 2000); - const logfilePath = path.join(environmentService.logsPath, processName); + const logfilePath = path.join(environmentService.logsPath, `${processName}.txt`); this.logger = new RotatingLogger(processName, logfilePath, 1024 * 1024 * 5, 6); } + // TODO, what about ARGS? trace(message: string, ...args: any[]): void { this.logger.trace(message); } diff --git a/src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts b/src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts index dfc6044522c..e311bee24de 100644 --- a/src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts +++ b/src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts @@ -48,7 +48,7 @@ suite('WorkspacesMainService', () => { } const environmentService = new TestEnvironmentService(parseArgs(process.argv), process.execPath); - const logService = new LegacyLogMainService('test', environmentService); + const logService = new LegacyLogMainService(environmentService); let service: TestWorkspacesMainService;