feat: logging levels - #42
Open
yCodeTech wants to merge 12 commits into
Open
Conversation
- Refactored `readJsonFile` util function to extract the json parsing into it's own `parseJsonContent` util function. This keeps the parsing separated from the reading of the file (DOT principle). - Added new `parseJsonContent` util function, and added the function call to the `readJsonFile` util.
…tput - Introduced `auto-comment-blocks.logLevel` setting to configure log verbosity with the options of `debug` (default), `info`, `error`, and `off` levels. Also added the new `logLevel` to the settings interface. - Added new `LogLevel` utils type to define the string union of the levels. - Changed the old unused `debugMode` property in Logger to the new `logLevel` property that accepts strings with the default set as "debug". - Changed the old unused `setDebugMode` method in Logger to the new `setLogLevel` method to set the new `logLevel` property to the desired log level. - Implemented the new `shouldLog` method with level weights to ensure the logger outputs logs at the correct level equated by the weighting system. The higher the level weight, the more verbose the logs get. Added the method call into the `info`, `debug`, and `error` methods. - Implemented dynamic log level adjustment on change of the `logLevel` setting, without extension reload.
- Move the logging of extension details from the Configuration `constructor` into the extension `activate` function. - Added new `important` method to Logger to output important logs that bypasses the log level and always be logged. To be used sparingly. - Added important output to the extension `activate` function to log the id and version of the extension.
- Fixed the info log in the `onDidOpenTextDocument` event to include the language ID, so we can see clearly in the output what language ID triggered the event.
- Added `prepareForLogging` ExtensionData method to remove `packageJSON` entry from the `extensionData` Map clone because it doesn't add anything useful to the debugging logs, so it just adds clutter. - Updated `getAll` ExtensionData method signature to allow a `prepareForLogging` boolean param. Also updated the method to clone the `extensionData` Map to avoid mutating the original data, and added the `prepareForLogging` method call.
There was a problem hiding this comment.
Pull request overview
Adds configurable logging levels to the extension, including a new settings key and updates to logger usage so output can be tuned (or disabled) by users.
Changes:
- Introduced a
LogLeveltype plus a newauto-comment-blocks.logLevelsetting and wiring to apply it at activation and on config changes. - Updated
Loggerto gatedebug/info/erroroutput based on the configured log level, and added an always-onimportantlog method. - Refactored
readJsonFileto delegate JSON parsing/error handling to a helper function.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.ts | Extracts JSON parsing/error handling into parseJsonContent. |
| src/logger.ts | Implements log-level filtering and adds an always-emitted important log. |
| src/interfaces/utils.ts | Adds LogLevel union type. |
| src/interfaces/settings.ts | Adds logLevel to the strongly-typed settings interface. |
| src/extensionData.ts | Adds prepareForLogging option to getAll and redacts packageJSON when logging. |
| src/extension.ts | Applies initial log level on activation; reacts to logLevel config changes; improves a log line’s detail. |
| src/configuration.ts | Removes activation-time debug logging (now handled in extension.ts). |
| package.json | Adds the auto-comment-blocks.logLevel setting definition. |
| .github/instructions/commit-message-generation.instructions.md | Adds commit message generation guidance for Copilot workflows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const documentOpenDisposable = vscode.workspace.onDidOpenTextDocument(() => { | ||
| logger.info("Active editor language changed, re-configuring comment blocks."); | ||
| const documentOpenDisposable = vscode.workspace.onDidOpenTextDocument((e) => { | ||
| logger.info(`Active editor language changed to "${e.languageId}", re-configuring comment blocks.`); |
- Changed log message output to use `append` instead of `appendLine` for better formatting. This is so that any meta data can start on the same line as the message, especially for objects. - Added leading space for meta data output. - Added a new line to the output with `appendLine` when no meta data is present, so that the next log can start on a new line.
- Added `logLevels` object to define log levels. - Changed the `LogLevel` type to create it's union type from the keys of the new `logLevels` object. - Updated `setLogLevel` method to validate log levels and default to "debug" if invalid. - Added `isValidLogLevel` method to check for valid log levels. This creates an array of the new `logLevel` object values and checks if the specified level is included to validate it.
The `getAll` ExtensionData method cloned the `extensionData` Map on every call, even when `prepareForLogging` was false, adding unnecessary processing when iterating over many extensions, which would have been a potential performance issue. - Moved cloning into `prepareForLogging` method, which now returns the redacted clone itself. - Refactored `getAll` method to only call `prepareForLogging` when needed, otherwise it reads directly from the original map.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.