Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log: Enhancements and cleaup #171325

Merged
merged 1 commit into from Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts
Expand Up @@ -48,8 +48,8 @@ import { MessagePortMainProcessService } from 'vs/platform/ipc/electron-browser/
import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { ILanguagePackService } from 'vs/platform/languagePacks/common/languagePacks';
import { NativeLanguagePackService } from 'vs/platform/languagePacks/node/languagePacks';
import { ConsoleLogger, ILoggerService, ILogService, MultiplexLogService } from 'vs/platform/log/common/log';
import { FollowerLogService, LoggerChannelClient, LogLevelChannel, LogLevelChannelClient } from 'vs/platform/log/common/logIpc';
import { ConsoleLogger, ILoggerService, ILogService } from 'vs/platform/log/common/log';
import { LoggerChannelClient } from 'vs/platform/log/common/logIpc';
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
Expand Down Expand Up @@ -115,6 +115,7 @@ import { UserDataSyncResourceProviderService } from 'vs/platform/userDataSync/co
import { ExtensionsContributions } from 'vs/code/electron-browser/sharedProcess/contrib/extensions';
import { ExtensionsProfileScannerService } from 'vs/platform/extensionManagement/electron-sandbox/extensionsProfileScannerService';
import { localize } from 'vs/nls';
import { LogService } from 'vs/platform/log/common/logService';

class SharedProcessMain extends Disposable {

Expand Down Expand Up @@ -216,17 +217,13 @@ class SharedProcessMain extends Disposable {
services.set(INativeEnvironmentService, environmentService);

// Logger
const logLevelClient = new LogLevelChannelClient(this.server.getChannel('logLevel', mainRouter));
const loggerService = new LoggerChannelClient(undefined, this.configuration.logLevel, logLevelClient.onDidChangeLogLevel, this.configuration.loggers, mainProcessService.getChannel('logger'));
const loggerService = new LoggerChannelClient(undefined, this.configuration.logLevel, this.configuration.loggers, mainProcessService.getChannel('logger'));
services.set(ILoggerService, loggerService);

// Log
const multiplexLogger = this._register(new MultiplexLogService([
this._register(new ConsoleLogger(this.configuration.logLevel)),
this._register(loggerService.createLogger(joinPath(URI.file(environmentService.logsPath), 'sharedprocess.log'), { id: 'sharedLog', name: localize('sharedLog', "Shared") }))
]));

const logService = this._register(new FollowerLogService(logLevelClient, multiplexLogger));
const logger = this._register(loggerService.createLogger(joinPath(URI.file(environmentService.logsPath), 'sharedprocess.log'), { id: 'sharedLog', name: localize('sharedLog', "Shared") }));
const consoleLogger = this._register(new ConsoleLogger(this.configuration.logLevel));
const logService = this._register(new LogService(logger, [consoleLogger]));
services.set(ILogService, logService);

// Lifecycle
Expand Down Expand Up @@ -374,11 +371,11 @@ class SharedProcessMain extends Disposable {
shortGraceTime: LocalReconnectConstants.ShortGraceTime,
scrollback: configurationService.getValue<number>(TerminalSettingId.PersistentSessionScrollback) ?? 100
},
localize('ptyHost', "Pty Host"),
configurationService,
environmentService,
logService,
loggerService,
uriIdentityService
loggerService
);
ptyHostService.initialize();

Expand All @@ -399,10 +396,6 @@ class SharedProcessMain extends Disposable {

private initChannels(accessor: ServicesAccessor): void {

// Log Level
const logLevelChannel = new LogLevelChannel(accessor.get(ILogService), accessor.get(ILoggerService));
this.server.registerChannel('logLevel', logLevelChannel);

// Extensions Management
const channel = new ExtensionManagementChannel(accessor.get(IExtensionManagementService), () => null);
this.server.registerChannel('extensions', channel);
Expand Down
8 changes: 1 addition & 7 deletions src/vs/code/electron-main/app.ts
Expand Up @@ -58,8 +58,7 @@ import { IIssueMainService, IssueMainService } from 'vs/platform/issue/electron-
import { IKeyboardLayoutMainService, KeyboardLayoutMainService } from 'vs/platform/keyboardLayout/electron-main/keyboardLayoutMainService';
import { ILaunchMainService, LaunchMainService } from 'vs/platform/launch/electron-main/launchMainService';
import { ILifecycleMainService, LifecycleMainPhase, ShutdownReason } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { ILoggerService, ILogService } from 'vs/platform/log/common/log';
import { LogLevelChannel } from 'vs/platform/log/common/logIpc';
import { ILogService } from 'vs/platform/log/common/log';
import { IMenubarMainService, MenubarMainService } from 'vs/platform/menubar/electron-main/menubarMainService';
import { INativeHostMainService, NativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
import { IProductService } from 'vs/platform/product/common/productService';
Expand Down Expand Up @@ -800,11 +799,6 @@ export class CodeApplication extends Disposable {
const externalTerminalChannel = ProxyChannel.fromService(accessor.get(IExternalTerminalMainService));
mainProcessElectronServer.registerChannel('externalTerminal', externalTerminalChannel);

// Log Level (main & shared process)
const logLevelChannel = new LogLevelChannel(accessor.get(ILogService), accessor.get(ILoggerService));
mainProcessElectronServer.registerChannel('logLevel', logLevelChannel);
sharedProcessClient.then(client => client.registerChannel('logLevel', logLevelChannel));

// Logger
const loggerChannel = new LoggerChannel(accessor.get(ILoggerMainService),);
mainProcessElectronServer.registerChannel('logger', loggerChannel);
Expand Down
20 changes: 11 additions & 9 deletions src/vs/code/electron-main/main.ts
Expand Up @@ -44,8 +44,8 @@ import { InstantiationService } from 'vs/platform/instantiation/common/instantia
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService';
import { ILifecycleMainService, LifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { BufferLogService } from 'vs/platform/log/common/bufferLog';
import { ConsoleMainLogger, getLogLevel, ILoggerService, ILogService, MultiplexLogService } from 'vs/platform/log/common/log';
import { BufferLogger } from 'vs/platform/log/common/bufferLog';
import { ConsoleMainLogger, getLogLevel, ILoggerService, ILogService } from 'vs/platform/log/common/log';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { IProtocolMainService } from 'vs/platform/protocol/electron-main/protocol';
Expand All @@ -69,6 +69,7 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { PROFILES_ENABLEMENT_CONFIG } from 'vs/platform/userDataProfile/common/userDataProfile';
import { ILoggerMainService, LoggerMainService } from 'vs/platform/log/electron-main/loggerService';
import { LogService } from 'vs/platform/log/common/logService';

/**
* The main VS Code entry point.
Expand Down Expand Up @@ -145,7 +146,7 @@ class CodeMain {
}
}

private createServices(): [IInstantiationService, IProcessEnvironment, IEnvironmentMainService, ConfigurationService, StateMainService, BufferLogService, IProductService, UserDataProfilesMainService] {
private createServices(): [IInstantiationService, IProcessEnvironment, IEnvironmentMainService, ConfigurationService, StateMainService, BufferLogger, IProductService, UserDataProfilesMainService] {
const services = new ServiceCollection();
const disposables = new DisposableStore();
process.once('exit', () => disposables.dispose());
Expand All @@ -159,11 +160,15 @@ class CodeMain {
const instanceEnvironment = this.patchEnvironment(environmentMainService); // Patch `process.env` with the instance's environment
services.set(IEnvironmentMainService, environmentMainService);

// Logger
const loggerService = new LoggerMainService(getLogLevel(environmentMainService));
services.set(ILoggerMainService, loggerService);

// Log: We need to buffer the spdlog logs until we are sure
// we are the only instance running, otherwise we'll have concurrent
// log file access on Windows (https://github.com/microsoft/vscode/issues/41218)
const bufferLogService = new BufferLogService();
const logService = disposables.add(new MultiplexLogService([new ConsoleMainLogger(getLogLevel(environmentMainService)), bufferLogService]));
const bufferLogger = new BufferLogger(loggerService.getLogLevel());
const logService = disposables.add(new LogService(bufferLogger, [new ConsoleMainLogger(loggerService.getLogLevel())]));
services.set(ILogService, logService);

// Files
Expand All @@ -176,9 +181,6 @@ class CodeMain {
const uriIdentityService = new UriIdentityService(fileService);
services.set(IUriIdentityService, uriIdentityService);

// Logger
services.set(ILoggerMainService, new LoggerMainService(logService));

// State
const stateMainService = new StateMainService(environmentMainService, logService, fileService);
services.set(IStateMainService, stateMainService);
Expand Down Expand Up @@ -215,7 +217,7 @@ class CodeMain {
// Protocol (instantiated early and not using sync descriptor for security reasons)
services.set(IProtocolMainService, new ProtocolMainService(environmentMainService, userDataProfilesMainService, logService));

return [new InstantiationService(services, true), instanceEnvironment, environmentMainService, configurationService, stateMainService, bufferLogService, productService, userDataProfilesMainService];
return [new InstantiationService(services, true), instanceEnvironment, environmentMainService, configurationService, stateMainService, bufferLogger, productService, userDataProfilesMainService];
}

private patchEnvironment(environmentMainService: IEnvironmentMainService): IProcessEnvironment {
Expand Down
11 changes: 6 additions & 5 deletions src/vs/code/node/cliProcessMain.ts
Expand Up @@ -39,7 +39,7 @@ import { InstantiationService } from 'vs/platform/instantiation/common/instantia
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ILanguagePackService } from 'vs/platform/languagePacks/common/languagePacks';
import { NativeLanguagePackService } from 'vs/platform/languagePacks/node/languagePacks';
import { ConsoleLogger, getLogLevel, ILogger, ILogService, LogLevel, MultiplexLogService } from 'vs/platform/log/common/log';
import { ConsoleLogger, getLogLevel, ILogger, ILogService, LogLevel } from 'vs/platform/log/common/log';
import { SpdLogLogger } from 'vs/platform/log/node/spdlogLog';
import { FilePolicyService } from 'vs/platform/policy/common/filePolicyService';
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
Expand All @@ -62,6 +62,7 @@ import { IUserDataProfilesService, PROFILES_ENABLEMENT_CONFIG } from 'vs/platfor
import { UserDataProfilesService } from 'vs/platform/userDataProfile/node/userDataProfile';
import { resolveMachineId } from 'vs/platform/telemetry/node/telemetryUtils';
import { ExtensionsProfileScannerService } from 'vs/platform/extensionManagement/node/extensionsProfileScannerService';
import { LogService } from 'vs/platform/log/common/logService';

class CliMain extends Disposable {

Expand Down Expand Up @@ -126,13 +127,13 @@ class CliMain extends Disposable {

// Log
const logLevel = getLogLevel(environmentService);
const loggers: ILogger[] = [];
loggers.push(new SpdLogLogger('cli', join(environmentService.logsPath, 'cli.log'), true, false, logLevel));
const spdLogLogger = new SpdLogLogger('cli', join(environmentService.logsPath, 'cli.log'), true, false, logLevel);
const otherLoggers: ILogger[] = [];
if (logLevel === LogLevel.Trace) {
loggers.push(new ConsoleLogger(logLevel));
otherLoggers.push(new ConsoleLogger(logLevel));
}

const logService = this._register(new MultiplexLogService(loggers));
const logService = this._register(new LogService(spdLogLogger, otherLoggers));
services.set(ILogService, logService);

// Files
Expand Down
3 changes: 2 additions & 1 deletion src/vs/editor/standalone/browser/standaloneServices.ts
Expand Up @@ -49,7 +49,7 @@ import { StandaloneServicesNLS } from 'vs/editor/common/standaloneStrings';
import { ClassifiedEvent, StrictPropertyCheck, OmitMetadata, IGDPRProperty } from 'vs/platform/telemetry/common/gdprTypings';
import { basename } from 'vs/base/common/resources';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ConsoleLogger, ILogService, LogService } from 'vs/platform/log/common/log';
import { ConsoleLogger, ILogService } from 'vs/platform/log/common/log';
import { IWorkspaceTrustManagementService, IWorkspaceTrustTransitionParticipant, IWorkspaceTrustUriInfo } from 'vs/platform/workspace/common/workspaceTrust';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
Expand Down Expand Up @@ -90,6 +90,7 @@ import 'vs/editor/common/services/languageFeaturesService';
import { DefaultConfiguration } from 'vs/platform/configuration/common/configurations';
import { WorkspaceEdit } from 'vs/editor/common/languages';
import { AudioCue, IAudioCueService, Sound } from 'vs/platform/audioCues/browser/audioCueService';
import { LogService } from 'vs/platform/log/common/logService';

class SimpleModel implements IResolvedTextEditorModel {

Expand Down
Expand Up @@ -20,11 +20,12 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
import { EnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { OPTIONS, parseArgs } from 'vs/platform/environment/node/argv';
import { HotExitConfiguration } from 'vs/platform/files/common/files';
import { ConsoleMainLogger, LogService } from 'vs/platform/log/common/log';
import { ConsoleMainLogger } from 'vs/platform/log/common/log';
import product from 'vs/platform/product/common/product';
import { IFolderBackupInfo, isFolderBackupInfo, IWorkspaceBackupInfo } from 'vs/platform/backup/common/backup';
import { IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { InMemoryTestStateMainService } from 'vs/platform/test/electron-main/workbenchTestServices';
import { LogService } from 'vs/platform/log/common/logService';

flakySuite('BackupMainService', () => {

Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/log/common/bufferLog.ts
Expand Up @@ -3,14 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AbstractMessageLogger, DEFAULT_LOG_LEVEL, ILogger, ILogService, log, LogLevel } from 'vs/platform/log/common/log';
import { AbstractMessageLogger, DEFAULT_LOG_LEVEL, ILogger, log, LogLevel } from 'vs/platform/log/common/log';

interface ILog {
level: LogLevel;
message: string;
}

export class BufferLogService extends AbstractMessageLogger implements ILogService {
export class BufferLogger extends AbstractMessageLogger {

declare readonly _serviceBrand: undefined;
private buffer: ILog[] = [];
Expand Down
12 changes: 6 additions & 6 deletions src/vs/platform/log/common/fileLog.ts
Expand Up @@ -8,8 +8,8 @@ import { VSBuffer } from 'vs/base/common/buffer';
import { basename, dirname, joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { ByteSize, FileOperationError, FileOperationResult, IFileService, whenProviderRegistered } from 'vs/platform/files/common/files';
import { BufferLogService } from 'vs/platform/log/common/bufferLog';
import { AbstractLoggerService, AbstractMessageLogger, ILogger, ILoggerOptions, ILoggerService, ILogService, LogLevel } from 'vs/platform/log/common/log';
import { BufferLogger } from 'vs/platform/log/common/bufferLog';
import { AbstractLoggerService, AbstractMessageLogger, ILogger, ILoggerOptions, ILoggerService, LogLevel } from 'vs/platform/log/common/log';

const MAX_FILE_SIZE = 5 * ByteSize.MB;

Expand Down Expand Up @@ -98,15 +98,15 @@ export class FileLogger extends AbstractMessageLogger implements ILogger {
export class FileLoggerService extends AbstractLoggerService implements ILoggerService {

constructor(
@ILogService logService: ILogService,
logLevel: LogLevel,
@IFileService private readonly fileService: IFileService,
) {
super(logService.getLevel(), logService.onDidChangeLogLevel);
super(logLevel);
}

protected doCreateLogger(resource: URI, logLevel: LogLevel, options?: ILoggerOptions): ILogger {
const logger = new BufferLogService(logLevel);
whenProviderRegistered(resource, this.fileService).then(() => (<BufferLogService>logger).logger = new FileLogger(resource, logger.getLevel(), !!options?.donotUseFormatters, this.fileService));
const logger = new BufferLogger(logLevel);
whenProviderRegistered(resource, this.fileService).then(() => logger.logger = new FileLogger(resource, logger.getLevel(), !!options?.donotUseFormatters, this.fileService));
return logger;
}
}