Replace console.log with VS Code output channel for better user visibility#54
Replace console.log with VS Code output channel for better user visibility#54
Conversation
Co-authored-by: norschel <12895005+norschel@users.noreply.github.com>
Co-authored-by: norschel <12895005+norschel@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a centralized VS Code output channel for logging and replaces all console.log/console.error calls in production code with structured logging functions, improving visibility in the VS Code Output panel.
- Added
src/logging.tswithinitializeOutputChannel,logInfo,logError,logDebug,showOutputChannel, anddisposeOutputChannel. - Updated all modules (
extension.ts, GitHub/Azure DevOps utilities, LLM parser, addCommand) to uselogInfo/logError. - Integrated output channel lifecycle in
activate/deactivateand added basic import tests insrc-tests/.
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/logging.ts | New logging utility managing a shared VS Code output channel |
| src/extension.ts | Initialized/disposed output channel and replaced console logs |
| src/github/gitHub.ts | Swapped console.log/error with logInfo/logError |
| src/llmBasedParser.ts | Replaced a diagnostic console.log with logInfo |
| src/azd/azd.ts | Replaced console.log/error with logInfo/logError |
| src/azd/workitems/azDevOpsWorkItemFunctions.ts | Added logInfo for PAT fallback diagnostics |
| src/addCommand.ts | Changed console.log to logError in error handler |
| src-tests/loggingTest.ts | Basic import-only script to verify logging function exports |
| src-tests/loggingTest.js | Duplicate JavaScript test for logging imports |
Comments suppressed due to low confidence (1)
src-tests/loggingTest.ts:7
- This test only verifies import availability. To improve coverage, add unit tests that mock vscode.OutputChannel and assert that logInfo/logError/logDebug produce correctly formatted output lines.
import { initializeOutputChannel, logInfo, logError, logDebug, showOutputChannel, disposeOutputChannel } from "../src/logging";
| export function logInfo(message: string): void { | ||
| if (outputChannel) { | ||
| outputChannel.appendLine(`[INFO] ${message}`); |
There was a problem hiding this comment.
The logging functions silently drop messages if the output channel isn't initialized. Consider automatically calling initializeOutputChannel() when outputChannel is null or logging a warning to alert developers of premature use.
| export function logInfo(message: string): void { | |
| if (outputChannel) { | |
| outputChannel.appendLine(`[INFO] ${message}`); | |
| export function logInfo(message: string): void { | |
| if (!outputChannel) { | |
| initializeOutputChannel(); | |
| } | |
| if (outputChannel) { | |
| outputChannel.appendLine(`[INFO] ${message}`); | |
| } else { | |
| console.warn("logInfo: Output channel is not initialized. Message dropped:", message); |
| @@ -0,0 +1,21 @@ | |||
| "use strict"; | |||
There was a problem hiding this comment.
This JavaScript test duplicates the TypeScript version in loggingTest.ts. Consolidate into a single test file to remove redundancy and simplify maintenance.
| "use strict"; | |
| // File removed. Functionality consolidated into loggingTest.ts. |
This PR addresses the feedback to replace
console.logusage in production extension code with a proper VS Code output channel, making diagnostic messages visible to users through the VS Code Output panel.Changes Made
New Output Channel Implementation
src/logging.tsutility with centralized output channel managementlogInfo(),logError(), andlogDebug()functions with proper log level formattingReplaced console.log Usage
Updated all production code files to use the new logging system:
src/extension.ts- Model selection and error logging (22 instances)src/github/gitHub.ts- Git repository operations (6 instances)src/llmBasedParser.ts- GitHub context operations (1 instance)src/addCommand.ts- Error handling (1 instance)src/azd/azd.ts- Azure DevOps operations (2 instances)src/azd/workitems/azDevOpsWorkItemFunctions.ts- Added the suggested authentication messageExample Implementation
The specific suggestion from the issue is now implemented:
Benefits
Verification
npm run compile)npm run lint)View > Output > VOCE DevOpsThe extension now provides better visibility into its operations while maintaining the same user experience for all existing features.
Fixes #53.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.