Skip to content

feat: logging levels - #42

Open
yCodeTech wants to merge 12 commits into
masterfrom
feat/logging-levels
Open

feat: logging levels#42
yCodeTech wants to merge 12 commits into
masterfrom
feat/logging-levels

Conversation

@yCodeTech

Copy link
Copy Markdown
Owner

No description provided.

- 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.
@yCodeTech yCodeTech added the enhancement New feature or quality of life enhancement label Jul 31, 2026
- 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.
Copilot AI review requested due to automatic review settings August 1, 2026 00:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 LogLevel type plus a new auto-comment-blocks.logLevel setting and wiring to apply it at activation and on config changes.
  • Updated Logger to gate debug/info/error output based on the configured log level, and added an always-on important log method.
  • Refactored readJsonFile to 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.

Comment thread src/logger.ts Outdated
Comment thread src/extensionData.ts Outdated
Comment thread src/extension.ts
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or quality of life enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants