Skip to content

Logging level is set after features are created and initialized, not before #1378

@glennsarti

Description

@glennsarti

System Details

  • Operating system name and version: Windows 10 - 1803
  • VS Code version: 1.24.0
  • PowerShell extension version: Commit ddc75b8
  • Output from $PSVersionTable: N/A

Issue Description

While working on a new feature for the extension, I noticed that I was unable to call writeError etc. on the logger object during Feature initialisation. I found this was due to a race-ish condition.

  1. We create the logging object here

logger = new Logger();

  1. We then create the features here

// Create features
extensionFeatures = [
new ConsoleFeature(),
new ExamplesFeature(),
new OpenInISEFeature(),
new GenerateBugReportFeature(sessionManager),
new ExpandAliasFeature(),
new ShowHelpFeature(),
new FindModuleFeature(),
new PesterTestsFeature(sessionManager),
new ExtensionCommandsFeature(logger),
new SelectPSSARulesFeature(),
new CodeActionsFeature(),
new NewFileOrProjectFeature(),
new DocumentFormatterFeature(logger, documentSelector),
new RemoteFilesFeature(),
new DebugSessionFeature(context, sessionManager),
new PickPSHostProcessFeature(),
new SpecifyScriptArgsFeature(context),
new HelpCompletionFeature(logger),
new CustomViewsFeature(),

  1. However, the debug log level is is only set at;

this.log.startNewLog(this.sessionSettings.developer.editorServicesLogLevel);

  1. Which is called from;
    sessionManager.start();

which is AFTER the features are created.

The race condition comes from how node schedules things on threads. Sometimes it was set in time for the feature creation, sometimes not.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions