Skip to content

Commit

Permalink
Align logging terminology to vscode output windows and remove editorS…
Browse files Browse the repository at this point in the history
…ervices from options definitions
  • Loading branch information
JustinGrote authored and andyleejordan committed Nov 15, 2024
1 parent 60ddcce commit 79954e2
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 64 deletions.
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ Logs provide context for what was happening when the issue occurred. **You shoul
your logs for any sensitive information you would not like to share online!**

* Before sending through logs, try and reproduce the issue with **log level set to
Diagnostic**. You can set this in the [VS Code Settings][]
Trace**. You can set this in the [VS Code Settings][]
(<kbd>Ctrl</kbd>+<kbd>,</kbd>) with:

```json
"powershell.developer.editorServicesLogLevel": "Diagnostic"
"powershell.developer.editorServicesLogLevel": "Trace"
```

* After you have captured the issue with the log level turned up, you may want to return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@
"Only log errors.",
"Disable all logging possible. No log files will be written!"
],
"markdownDescription": "Sets the log verbosity for both the extension and its LSP server, PowerShell Editor Services. **Please set to `Diagnostic` when recording logs for a bug report!**"
"markdownDescription": "Sets the log verbosity for both the extension and its LSP server, PowerShell Editor Services. **Please set to `Trace` when recording logs for a bug report!**"
},
"powershell.developer.editorServicesWaitForDebugger": {
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
telemetryReporter = new TelemetryReporter(TELEMETRY_KEY);

const settings = getSettings();
logger.writeVerbose(`Loaded settings:\n${JSON.stringify(settings, undefined, 2)}`);
logger.writeDebug(`Loaded settings:\n${JSON.stringify(settings, undefined, 2)}`);

languageConfigurationDisposable = vscode.languages.setLanguageConfiguration(
PowerShellLanguageId,
Expand Down
12 changes: 6 additions & 6 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ export class DebugSessionFeature extends LanguageClientConsumer
// Create or show the debug terminal (either temporary or session).
this.sessionManager.showDebugTerminal(true);

this.logger.writeVerbose(`Connecting to pipe: ${sessionDetails.debugServicePipeName}`);
this.logger.writeVerbose(`Debug configuration: ${JSON.stringify(session.configuration, undefined, 2)}`);
this.logger.writeDebug(`Connecting to pipe: ${sessionDetails.debugServicePipeName}`);
this.logger.writeDebug(`Debug configuration: ${JSON.stringify(session.configuration, undefined, 2)}`);

return new DebugAdapterNamedPipeServer(sessionDetails.debugServicePipeName);
}
Expand Down Expand Up @@ -424,7 +424,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
// The dispose shorthand demonry for making an event one-time courtesy of: https://github.com/OmniSharp/omnisharp-vscode/blob/b8b07bb12557b4400198895f82a94895cb90c461/test/integrationTests/launchConfiguration.integration.test.ts#L41-L45
startDebugEvent.dispose();

this.logger.writeVerbose(`Debugger session detected: ${dotnetAttachSession.name} (${dotnetAttachSession.id})`);
this.logger.writeDebug(`Debugger session detected: ${dotnetAttachSession.name} (${dotnetAttachSession.id})`);

tempConsoleDotnetAttachSession = dotnetAttachSession;

Expand All @@ -434,7 +434,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
// Makes the event one-time
stopDebugEvent.dispose();

this.logger.writeVerbose(`Debugger session terminated: ${tempConsoleSession.name} (${tempConsoleSession.id})`);
this.logger.writeDebug(`Debugger session terminated: ${tempConsoleSession.name} (${tempConsoleSession.id})`);

// HACK: As of 2023-08-17, there is no vscode debug API to request the C# debugger to detach, so we send it a custom DAP request instead.
const disconnectRequest: DebugProtocol.DisconnectRequest = {
Expand Down Expand Up @@ -462,8 +462,8 @@ export class DebugSessionFeature extends LanguageClientConsumer
// Start a child debug session to attach the dotnet debugger
// TODO: Accommodate multi-folder workspaces if the C# code is in a different workspace folder
await debug.startDebugging(undefined, dotnetAttachConfig, session);
this.logger.writeVerbose(`Dotnet attach debug configuration: ${JSON.stringify(dotnetAttachConfig, undefined, 2)}`);
this.logger.writeVerbose(`Attached dotnet debugger to process: ${pid}`);
this.logger.writeDebug(`Dotnet attach debug configuration: ${JSON.stringify(dotnetAttachConfig, undefined, 2)}`);
this.logger.writeDebug(`Attached dotnet debugger to process: ${pid}`);
}

return this.tempSessionDetails;
Expand Down
8 changes: 4 additions & 4 deletions src/features/ExternalApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ExternalApiFeature implements IPowerShellExtensionClient {
string session uuid
*/
public registerExternalExtension(id: string, apiVersion = "v1"): string {
this.logger.writeVerbose(`Registering extension '${id}' for use with API version '${apiVersion}'.`);
this.logger.writeDebug(`Registering extension '${id}' for use with API version '${apiVersion}'.`);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [_name, externalExtension] of ExternalApiFeature.registeredExternalExtension) {
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ExternalApiFeature implements IPowerShellExtensionClient {
true if it worked, otherwise throws an error.
*/
public unregisterExternalExtension(uuid = ""): boolean {
this.logger.writeVerbose(`Unregistering extension with session UUID: ${uuid}`);
this.logger.writeDebug(`Unregistering extension with session UUID: ${uuid}`);
if (!ExternalApiFeature.registeredExternalExtension.delete(uuid)) {
throw new Error(`No extension registered with session UUID: ${uuid}`);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ export class ExternalApiFeature implements IPowerShellExtensionClient {
*/
public async getPowerShellVersionDetails(uuid = ""): Promise<IExternalPowerShellDetails> {
const extension = this.getRegisteredExtension(uuid);
this.logger.writeVerbose(`Extension '${extension.id}' called 'getPowerShellVersionDetails'.`);
this.logger.writeDebug(`Extension '${extension.id}' called 'getPowerShellVersionDetails'.`);

await this.sessionManager.waitUntilStarted();
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
Expand Down Expand Up @@ -162,7 +162,7 @@ export class ExternalApiFeature implements IPowerShellExtensionClient {
*/
public async waitUntilStarted(uuid = ""): Promise<void> {
const extension = this.getRegisteredExtension(uuid);
this.logger.writeVerbose(`Extension '${extension.id}' called 'waitUntilStarted'.`);
this.logger.writeDebug(`Extension '${extension.id}' called 'waitUntilStarted'.`);
await this.sessionManager.waitUntilStarted();
}

Expand Down
24 changes: 12 additions & 12 deletions src/features/UpdatePowerShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ export class UpdatePowerShell {
private shouldCheckForUpdate(): boolean {
// Respect user setting.
if (!this.sessionSettings.promptToUpdatePowerShell) {
this.logger.writeVerbose("Setting 'promptToUpdatePowerShell' was false.");
this.logger.writeDebug("Setting 'promptToUpdatePowerShell' was false.");
return false;
}

// Respect environment configuration.
if (process.env.POWERSHELL_UPDATECHECK?.toLowerCase() === "off") {
this.logger.writeVerbose("Environment variable 'POWERSHELL_UPDATECHECK' was 'Off'.");
this.logger.writeDebug("Environment variable 'POWERSHELL_UPDATECHECK' was 'Off'.");
return false;
}

// Skip prompting when using Windows PowerShell for now.
if (this.localVersion.compare("6.0.0") === -1) {
// TODO: Maybe we should announce PowerShell Core?
this.logger.writeVerbose("Not prompting to update Windows PowerShell.");
this.logger.writeDebug("Not prompting to update Windows PowerShell.");
return false;
}

Expand All @@ -78,13 +78,13 @@ export class UpdatePowerShell {

// Skip if PowerShell is self-built, that is, this contains a commit hash.
if (commit.length >= 40) {
this.logger.writeVerbose("Not prompting to update development build.");
this.logger.writeDebug("Not prompting to update development build.");
return false;
}

// Skip if preview is a daily build.
if (daily.toLowerCase().startsWith("daily")) {
this.logger.writeVerbose("Not prompting to update daily build.");
this.logger.writeDebug("Not prompting to update daily build.");
return false;
}
}
Expand All @@ -106,7 +106,7 @@ export class UpdatePowerShell {
// "ReleaseTag": "v7.2.7"
// }
const data = await response.json();
this.logger.writeVerbose(`Received from '${url}':\n${JSON.stringify(data, undefined, 2)}`);
this.logger.writeDebug(`Received from '${url}':\n${JSON.stringify(data, undefined, 2)}`);
return data.ReleaseTag;
}

Expand All @@ -115,26 +115,26 @@ export class UpdatePowerShell {
return undefined;
}

this.logger.writeVerbose("Checking for PowerShell update...");
this.logger.writeDebug("Checking for PowerShell update...");
const tags: string[] = [];
if (process.env.POWERSHELL_UPDATECHECK?.toLowerCase() === "lts") {
// Only check for update to LTS.
this.logger.writeVerbose("Checking for LTS update...");
this.logger.writeDebug("Checking for LTS update...");
const tag = await this.getRemoteVersion(UpdatePowerShell.LTSBuildInfoURL);
if (tag != undefined) {
tags.push(tag);
}
} else {
// Check for update to stable.
this.logger.writeVerbose("Checking for stable update...");
this.logger.writeDebug("Checking for stable update...");
const tag = await this.getRemoteVersion(UpdatePowerShell.StableBuildInfoURL);
if (tag != undefined) {
tags.push(tag);
}

// Also check for a preview update.
if (this.localVersion.prerelease.length > 0) {
this.logger.writeVerbose("Checking for preview update...");
this.logger.writeDebug("Checking for preview update...");
const tag = await this.getRemoteVersion(UpdatePowerShell.PreviewBuildInfoURL);
if (tag != undefined) {
tags.push(tag);
Expand Down Expand Up @@ -181,11 +181,11 @@ export class UpdatePowerShell {

// If the user cancels the notification.
if (!result) {
this.logger.writeVerbose("User canceled PowerShell update prompt.");
this.logger.writeDebug("User canceled PowerShell update prompt.");
return;
}

this.logger.writeVerbose(`User said '${UpdatePowerShell.promptOptions[result.id].title}'.`);
this.logger.writeDebug(`User said '${UpdatePowerShell.promptOptions[result.id].title}'.`);

switch (result.id) {
// Yes
Expand Down
8 changes: 4 additions & 4 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { LogOutputChannel, LogLevel, window, Event } from "vscode";
export interface ILogger {
write(message: string, ...additionalMessages: string[]): void;
writeAndShowInformation(message: string, ...additionalMessages: string[]): Promise<void>;
writeDiagnostic(message: string, ...additionalMessages: string[]): void;
writeVerbose(message: string, ...additionalMessages: string[]): void;
writeTrace(message: string, ...additionalMessages: string[]): void;
writeDebug(message: string, ...additionalMessages: string[]): void;
writeWarning(message: string, ...additionalMessages: string[]): void;
writeAndShowWarning(message: string, ...additionalMessages: string[]): Promise<void>;
writeError(message: string, ...additionalMessages: string[]): void;
Expand Down Expand Up @@ -56,11 +56,11 @@ export class Logger implements ILogger {
}
}

public writeDiagnostic(message: string, ...additionalMessages: string[]): void {
public writeTrace(message: string, ...additionalMessages: string[]): void {
this.writeAtLevel(LogLevel.Trace, message, ...additionalMessages);
}

public writeVerbose(message: string, ...additionalMessages: string[]): void {
public writeDebug(message: string, ...additionalMessages: string[]): void {
this.writeAtLevel(LogLevel.Debug, message, ...additionalMessages);
}

Expand Down
10 changes: 5 additions & 5 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export class PowerShellProcess {
startEditorServices);
} else {
// Otherwise use -EncodedCommand for better quote support.
this.logger.writeVerbose("Using Base64 -EncodedCommand but logging as -Command equivalent.");
this.logger.writeDebug("Using Base64 -EncodedCommand but logging as -Command equivalent.");
powerShellArgs.push(
"-EncodedCommand",
Buffer.from(startEditorServices, "utf16le").toString("base64"));
}

this.logger.writeVerbose(`Starting process: ${this.exePath} ${powerShellArgs.slice(0, -2).join(" ")} -Command ${startEditorServices}`);
this.logger.writeDebug(`Starting process: ${this.exePath} ${powerShellArgs.slice(0, -2).join(" ")} -Command ${startEditorServices}`);

// Make sure no old session file exists
await this.deleteSessionFile(this.sessionFilePath);
Expand Down Expand Up @@ -174,7 +174,7 @@ export class PowerShellProcess {
}

public dispose(): void {
this.logger.writeVerbose(`Disposing PowerShell process with PID: ${this.pid}`);
this.logger.writeDebug(`Disposing PowerShell process with PID: ${this.pid}`);

void this.deleteSessionFile(this.sessionFilePath);

Expand Down Expand Up @@ -227,7 +227,7 @@ export class PowerShellProcess {
const warnAt = numOfTries - PowerShellProcess.warnUserThreshold;

// Check every second.
this.logger.writeVerbose(`Waiting for session file: ${this.sessionFilePath}`);
this.logger.writeDebug(`Waiting for session file: ${this.sessionFilePath}`);
for (let i = numOfTries; i > 0; i--) {
if (cancellationToken.isCancellationRequested) {
this.logger.writeWarning("Canceled while waiting for session file.");
Expand All @@ -240,7 +240,7 @@ export class PowerShellProcess {
}

if (await utils.checkIfFileExists(this.sessionFilePath)) {
this.logger.writeVerbose("Session file found.");
this.logger.writeDebug("Session file found.");
return await this.readSessionFile(this.sessionFilePath);
}

Expand Down
Loading

0 comments on commit 79954e2

Please sign in to comment.