Skip to content

🧹 Refactor logging to use OutputChannel in extension.ts#47

Open
nur-srijan wants to merge 1 commit intomainfrom
fix/excessive-logging-1031586275283695815
Open

🧹 Refactor logging to use OutputChannel in extension.ts#47
nur-srijan wants to merge 1 commit intomainfrom
fix/excessive-logging-1031586275283695815

Conversation

@nur-srijan
Copy link
Copy Markdown
Owner

🎯 What: The code health issue addressed
The excessive use of console.log, console.warn, and console.error in src/extension.ts has been replaced with a dedicated vscode.OutputChannel.

💡 Why: How this improves maintainability
Using a dedicated vscode.OutputChannel instead of raw console statements is standard practice for VS Code extensions. It keeps the extension host logs clean, directs logs specifically to an easy-to-find channel for debugging the extension explicitly, and is much better for production environments.

Verification: How you confirmed the change is safe

  • Executed pnpm test:ci and confirmed all 21 unit tests passed successfully.
  • Verified that all console.log, console.warn, and console.error statements in src/extension.ts were completely removed.
  • Validated via automated code review that the refactoring is safe and correctly handles output channel initialization and destruction in activate() and deactivate().

Result: The improvement achieved
The src/extension.ts codebase is now cleaner, uses proper VS Code APIs for logging, avoids polluting stdout/stderr, and correctly handles errors through formatted output channel updates.


PR created automatically by Jules for task 1031586275283695815 started by @nur-srijan

Refactors `src/extension.ts` to use a dedicated `vscode.OutputChannel` instead of `console.log`, `console.warn`, and `console.error` for improved maintainability and better user experience in production environments. Errors and informational messages are now correctly piped through the unified `log` function. Also makes `deactivate` hook async to correctly wait for browser cleanup.

Co-authored-by: nur-srijan <198181700+nur-srijan@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the logging mechanism within the extension to align with VS Code's recommended practices. By transitioning from direct console output to a dedicated vscode.OutputChannel, the change enhances maintainability, provides a cleaner logging experience for users, and improves debugging capabilities by centralizing extension-specific logs.

Highlights

  • Logging Refactor: Replaced all instances of console.log, console.warn, and console.error in src/extension.ts with a dedicated vscode.OutputChannel for improved logging practices.
  • Custom Log Function: Introduced a new log helper function to centralize logging to the OutputChannel, distinguishing between informational and error messages.
  • Output Channel Lifecycle Management: Ensured proper initialization of the OutputChannel in the activate function and its disposal in the deactivate function to prevent resource leaks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/extension.ts
    • Replaced direct console.log, console.warn, and console.error calls with a new log function.
    • Implemented vscode.OutputChannel for structured logging.
    • Managed the lifecycle of the OutputChannel by creating it on activation and disposing of it on deactivation.
Activity
  • The pull request was created automatically by Jules for task 1031586275283695815, started by @nur-srijan.
  • All 21 unit tests passed successfully after executing pnpm test:ci.
  • Verified that all console.log, console.warn, and console.error statements in src/extension.ts were removed.
  • Automated code review validated the refactoring for safety and correct handling of output channel initialization and destruction.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully refactors the logging from console.* calls to a dedicated vscode.OutputChannel, which is a great improvement for a VS Code extension. The implementation correctly initializes and disposes of the output channel. My feedback focuses on further improving the new logging utility by introducing structured log levels (e.g., INFO, WARN, ERROR) instead of a boolean flag. This will restore the distinction for warnings that was present with console.warn and enhance the overall maintainability and debuggability of the extension's logging.

Comment thread src/extension.ts
Comment on lines +21 to +27
function log(message: string, isError: boolean = false): void {
if (!outputChannel) {
return;
}
const prefix = isError ? '[ERROR]' : '[INFO]';
outputChannel.appendLine(`${prefix} ${message}`);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current log function only supports info and error levels via a boolean flag. This loses the distinction of warnings (e.g., console.warn was used previously). To improve logging clarity and maintainability, I suggest introducing an enum for log levels. This allows for more granular logging (e.g., INFO, WARN, ERROR) and makes the log output easier to parse and filter. I'll provide suggestions for updating the call sites in subsequent comments.

enum LogLevel {
    Info = 'INFO',
    Warn = 'WARN',
    Error = 'ERROR',
}

function log(message: string, level: LogLevel = LogLevel.Info): void {
    if (!outputChannel) {
        return;
    }
    outputChannel.appendLine(`[${level}] ${message}`);
}

Comment thread src/extension.ts
await browserInstance.close();
} catch (error) {
console.error('Error closing browser instance:', error);
log(`Error closing browser instance: ${error instanceof Error ? error.message : String(error)}`, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the proposed change to the log function, this call should be updated to use the LogLevel enum for error logging.

                log(`Error closing browser instance: ${error instanceof Error ? error.message : String(error)}`, LogLevel.Error);

Comment thread src/extension.ts
browserInstance = null;
} catch (error) {
console.error('Error cleaning up browser instance:', error);
log(`Error cleaning up browser instance: ${error instanceof Error ? error.message : String(error)}`, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the proposed change to the log function, this call should be updated to use the LogLevel enum for error logging.

            log(`Error cleaning up browser instance: ${error instanceof Error ? error.message : String(error)}`, LogLevel.Error);

Comment thread src/extension.ts
} catch (error) {
vscode.window.showErrorMessage(`Failed to export PDF: ${error instanceof Error ? error.message : String(error)}`);
console.error('PDF Export Error:', error);
log(`PDF Export Error: ${error instanceof Error ? error.message : String(error)}`, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the proposed change to the log function, this call should be updated to use the LogLevel enum for error logging.

                            log(`PDF Export Error: ${error instanceof Error ? error.message : String(error)}`, LogLevel.Error);

Comment thread src/extension.ts
}
} catch (e) {
console.warn('Failed to delete temp HTML file:', e);
log(`Failed to delete temp HTML file: ${e instanceof Error ? e.message : String(e)}`, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This was previously a console.warn. Failing to delete a temporary file is not a critical error that stops the extension, so it's better to log it as a warning instead of an error using the new LogLevel.Warn.

                                    log(`Failed to delete temp HTML file: ${e instanceof Error ? e.message : String(e)}`, LogLevel.Warn);

Comment thread src/extension.ts

if (page && !page.isClosed()) {
await page.close().catch(console.error);
await page.close().catch(err => log(`Error closing page: ${err instanceof Error ? err.message : String(err)}`, true));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the proposed change to the log function, this call should be updated to use the LogLevel enum for error logging.

                                await page.close().catch(err => log(`Error closing page: ${err instanceof Error ? err.message : String(err)}`, LogLevel.Error));

Comment thread src/extension.ts
});
} catch (error) {
console.error('Error in PDF export:', error);
log(`Error in PDF export: ${error instanceof Error ? error.message : String(error)}`, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the proposed change to the log function, this call should be updated to use the LogLevel enum for error logging.

                    log(`Error in PDF export: ${error instanceof Error ? error.message : String(error)}`, LogLevel.Error);

Comment thread src/extension.ts
log('activate() completed successfully');
} catch (error) {
console.error('Markdown Rich Preview & Export: activate() failed:', error);
log(`activate() failed: ${error instanceof Error ? error.message : String(error)}`, true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the proposed change to the log function, this call should be updated to use the LogLevel enum for error logging.

        log(`activate() failed: ${error instanceof Error ? error.message : String(error)}`, LogLevel.Error);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant