🧹 Refactor logging to use OutputChannel in extension.ts#47
🧹 Refactor logging to use OutputChannel in extension.ts#47nur-srijan wants to merge 1 commit intomainfrom
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello, 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 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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.
| function log(message: string, isError: boolean = false): void { | ||
| if (!outputChannel) { | ||
| return; | ||
| } | ||
| const prefix = isError ? '[ERROR]' : '[INFO]'; | ||
| outputChannel.appendLine(`${prefix} ${message}`); | ||
| } |
There was a problem hiding this comment.
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}`);
}| 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); |
| 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); |
| } 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); |
| } | ||
| } 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); |
There was a problem hiding this comment.
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);|
|
||
| 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)); |
| }); | ||
| } catch (error) { | ||
| console.error('Error in PDF export:', error); | ||
| log(`Error in PDF export: ${error instanceof Error ? error.message : String(error)}`, true); |
| 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); |
🎯 What: The code health issue addressed
The excessive use of
console.log,console.warn, andconsole.errorinsrc/extension.tshas been replaced with a dedicatedvscode.OutputChannel.💡 Why: How this improves maintainability
Using a dedicated
vscode.OutputChannelinstead of rawconsolestatements 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
pnpm test:ciand confirmed all 21 unit tests passed successfully.console.log,console.warn, andconsole.errorstatements insrc/extension.tswere completely removed.activate()anddeactivate().✨ Result: The improvement achieved
The
src/extension.tscodebase 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