-
Notifications
You must be signed in to change notification settings - Fork 332
Gate debug logs behind DEBUG environment variable using debug npm package
#9396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ug logs Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
| */ | ||
| export const ENABLE_SERVER_COMPILE_LOGGING = "ENABLE_SERVER_COMPILE_LOGGING"; | ||
| export const ENABLE_UPDATE_MANAGER_LOGGING = "ENABLE_UPDATE_MANAGER_LOGGING"; | ||
| export const ENABLE_COMPILE_CONFIG_LOGGING = "ENABLE_COMPILE_CONFIG_LOGGING"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's change to use DEBUG=area1,area2 in nodejs pattern for this, please also change the other enable...logging enviornment variable too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot , let's change to use DEBUG=area1,area2 in nodejs pattern instead of individual env var for this, please also change the other enable...logging enviornment variable too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use Node.js DEBUG pattern in commit 94bf93f.
Now uses DEBUG=typespec:compile,typespec:config instead of individual environment variables. Supports wildcards like DEBUG=typespec:*.
All three existing logging areas have been migrated:
typespec:compile(was ENABLE_SERVER_COMPILE_LOGGING)typespec:update(was ENABLE_UPDATE_MANAGER_LOGGING)typespec:config(was ENABLE_COMPILE_CONFIG_LOGGING)
Changed from individual ENABLE_*_LOGGING environment variables to Node.js style DEBUG pattern supporting comma-separated areas and wildcards. Usage examples: DEBUG=typespec:compile DEBUG=typespec:* DEBUG=typespec:compile,typespec:config Debug areas: - typespec:compile (previously ENABLE_SERVER_COMPILE_LOGGING) - typespec:update (previously ENABLE_UPDATE_MANAGER_LOGGING) - typespec:config (previously ENABLE_COMPILE_CONFIG_LOGGING) Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
| export const DebugAreas = { | ||
| SERVER_COMPILE: "typespec:compile", | ||
| UPDATE_MANAGER: "typespec:update", | ||
| COMPILE_CONFIG: "typespec:config", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot keep the original string between enable and logging, i.e. server_compile -> "typespec::server_compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to preserve original naming in commit b4bcd2d.
Debug areas now use:
typespec:server_compiletypespec:update_managertypespec:compile_config
| * DEBUG=typespec:* | ||
| * DEBUG=typespec:compile,typespec:config | ||
| */ | ||
| export function isDebugEnabled(area: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot reuse existing common package like 'debug'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to use the debug npm package in commit 451c4e0.
Changes:
- Added
debug@~4.4.0and@types/debug@~4.1.12as dependencies - Replaced custom
isDebugEnabled()with standard debug package loggers - All files now use
debugLoggers.*.enabledto check if debugging is active
The debug package provides standard Node.js debugging with wildcards, namespaces, and better performance.
| SERVER_COMPILE: "typespec:compile", | ||
| UPDATE_MANAGER: "typespec:update", | ||
| COMPILE_CONFIG: "typespec:config", | ||
| } as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot , also updated related comment in the launch file in vscode workspace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated .vscode/launch.json in commit 451c4e0.
Replaced old environment variable comments (ENABLE_SERVER_COMPILE_LOGGING, ENABLE_UPDATE_MANAGER_LOGGING) with DEBUG pattern documentation showing usage examples:
DEBUG=typespec:server_compilefor specific areasDEBUG=typespec:*for all areasDEBUG=typespec:server_compile,typespec:compile_configfor multiple areas
Changed debug area names to preserve the original convention: - typespec:server_compile (was typespec:compile) - typespec:update_manager (was typespec:update) - typespec:compile_config (was typespec:config) This maintains consistency with the original ENABLE_*_LOGGING variable names. Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
- Added `debug` package (v4.4.0) as dependency - Added `@types/debug` as dev dependency - Replaced custom isDebugEnabled() with debug package loggers - Updated .vscode/launch.json to document DEBUG env var usage - Removed old ENABLE_*_LOGGING environment variable comments The debug package provides standard Node.js debugging with namespace support, wildcards, and better performance than the custom implementation. Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
debug npm package
.vscode/launch.json
Outdated
| // "DEBUG": "typespec:*" - Enable all typespec debug logs | ||
| // "DEBUG": "typespec:server_compile,typespec:compile_config" - Enable multiple areas | ||
| //"DEBUG": "typespec:server_compile,typespec:update_manager,typespec:compile_config", | ||
| //"ENABLE_LM_LOGGING": "true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot , you missed the enable_lm_logging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added documentation for ENABLE_LM_LOGGING in commit ca30a74.
Added a comment clarifying that ENABLE_LM_LOGGING is separate from the DEBUG environment variable logging system and is used specifically for Language Model logging in the typespec-vscode extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot , also do the same refactor to use debug log area for the code in typespec-vscode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored typespec-vscode to use the debug package in commit 42c1d4f.
Changes:
- Added
debug@~4.4.0and@types/debug@~4.1.12to typespec-vscode - Replaced
ENABLE_LM_LOGGINGwithdebugLoggers.lmusing namespacetypespec:lm - Updated
.vscode/launch.jsonto documentDEBUG=typespec:lmusage
Language Model logging now follows the same DEBUG pattern as compiler logging. Enable with DEBUG=typespec:lm or DEBUG=typespec:*
Added a comment to clarify that ENABLE_LM_LOGGING is separate from the DEBUG environment variable logging system and is used specifically for Language Model logging in the typespec-vscode extension. Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
- Added `debug@~4.4.0` as dependency to typespec-vscode - Added `@types/debug@~4.1.12` as dev dependency - Replaced ENABLE_LM_LOGGING with debug logger (typespec:lm) - Updated const.ts to export debugLoggers.lm - Updated language-model.ts to use debugLoggers.lm.enabled - Updated .vscode/launch.json to document DEBUG=typespec:lm usage Language Model logging now follows the same DEBUG pattern as compiler logging, enabling it with DEBUG=typespec:lm or DEBUG=typespec:* Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Summary
This PR fixes the issue of LSP spamming irrelevant debug messages in the console on every compilation (which happens on nearly every keystroke with debounce).
Changes Made
Refactored to use the
debugnpm package (per review feedback):debugpackage (v4.4.0) as a dependency to both@typespec/compilerandtypespec-vscode@types/debugas a dev dependency to both packagesisDebugEnabled()function with standarddebugpackage loggersDebug areas defined (preserving original naming):
typespec:server_compile- Server compilation debug logs (previouslyENABLE_SERVER_COMPILE_LOGGING)typespec:update_manager- Update manager debug logs (previouslyENABLE_UPDATE_MANAGER_LOGGING)typespec:compile_config- Compilation config debug logs (previouslyENABLE_COMPILE_CONFIG_LOGGING)typespec:lm- Language Model debug logs (previouslyENABLE_LM_LOGGING)Updated .vscode/launch.json:
Updated files in @typespec/compiler:
constants.ts- Usesdebugpackage, exportsdebugLoggersentrypoint-resolver.ts- UsesdebugLoggers.compileConfig.enabledcompile-service.ts- UsesdebugLoggers.compileConfig.enabledserver-compile-manager.ts- UsesdebugLoggers.serverCompile.enabledupdate-manager.ts- UsesdebugLoggers.updateManager.enabledserverlib.ts- UsesdebugLoggers.compileConfig.enabledUpdated files in typespec-vscode:
package.json- Addeddebugdependency and@types/debugdev dependencyconst.ts- ExportsdebugLoggers.lminstead ofENABLE_LM_LOGGINGconstantlanguage-model.ts- UsesdebugLoggers.lm.enabledinstead of checking environment variableUpdated workspace configuration:
.vscode/launch.json- Updated comments to document unified DEBUG env var usageHow It Works
By default, all debug messages are suppressed. Users can enable them when troubleshooting using the standard Node.js DEBUG environment variable:
The
debugpackage provides:typespec:*)Test Results
Original prompt
💡 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.