Skip to content

feat: add wildcard support for logger configuration#17627

Open
ankitsharma101 wants to merge 6 commits into
eclipse-theia:masterfrom
ankitsharma101:feature/logger-wildcard-support
Open

feat: add wildcard support for logger configuration#17627
ankitsharma101 wants to merge 6 commits into
eclipse-theia:masterfrom
ankitsharma101:feature/logger-wildcard-support

Conversation

@ankitsharma101

Copy link
Copy Markdown
Contributor

What it does

Fixes #17466

This PR introduces wildcard and regex support for logger configuration, allowing developers to configure multiple loggers using a single rule (e.g., "ai-core*": "error", "*Token*": "warn") without needing to explicitly list every sub-service.

Implementation Details:

  • Added wildcardRegexCache to LogLevelCliContribution to ensure regex compilation only happens once per pattern for optimal performance.
  • Updated logLevelFor to iterate through configured levels, respecting the "last one wins" rule for wildcard specificity.
  • Added getWildcardRegex to safely escape standard regex characters in the user's config before injecting the .* wildcard matcher.
  • Test Refactor: Cleaned up legacy unhandled Promises in older setArguments tests to ensure strict type compliance and reliable CLI fallbacks.

How to test

1. Automated Tests
Run the core test suite to verify the new wildcard matching logic and the patched legacy tests:
yarn --cwd packages/core test

2. End-to-End Test
A sample log-config.json has been added to the browser example.

  1. Navigate to the browser example: cd examples/browser
  2. Build the application: yarn build
  3. Start the application: yarn start
  4. Observe the terminal output. You should see Successfully read new log config from .../log-config.json and notice that the plugin loggers perfectly respect the wildcard rules defined in the file.

Follow-ups

None currently identified. The regex cache ensures this scales well even if developers provide massive configuration files.

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

@github-project-automation github-project-automation Bot moved this to Waiting on reviewers in PR Backlog Jun 5, 2026
@ankitsharma101 ankitsharma101 force-pushed the feature/logger-wildcard-support branch from dabcea8 to f047a40 Compare June 5, 2026 14:21
@sdirix sdirix self-requested a review June 8, 2026 10:23

@sdirix sdirix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this first implementation. Please see my comments.

Comment thread packages/core/src/node/logger-cli-contribution.ts Outdated
Comment thread packages/core/src/node/logger-cli-contribution.ts
Comment thread packages/core/src/node/logger-cli-contribution.ts
Comment thread packages/core/src/node/logger-cli-contribution.spec.ts Outdated
Comment thread examples/browser/log-config.json Outdated
Comment thread examples/browser/log-config.json Outdated
@github-project-automation github-project-automation Bot moved this from Waiting on reviewers to Waiting on author in PR Backlog Jun 8, 2026
@ankitsharma101

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, Stefan! I've fully addressed your feedback across the board:

Memory Leak: Added a cache.clear() call inside slurpLogConfigFile so the cache cleanly wipes whenever a user modifies the log configuration file at runtime.

Performance Optimization: Refactored logLevelFor to execute a fast O(1) perfect match lookup upfront. If an exact match isn't present, it iterates through the keys backward and short-circuits on the first wildcard match to respect the "last one wins" specificity rule efficiently.

Test Refactor: Cleaned up the testing architecture. The wildcard tests no longer mutate private state using as unknown as Record<string, unknown> and instead leverage a helper that tests everything cleanly via the public CLI API.

Sensible Defaults: Updated the browser example log-config.json with a lightweight, realistic use case that won't obscure verbose logging during core active AI development.

Documentation: Documented the newly introduced wildcard feature, precedence tiers, and exact match priority within packages/core/README.md.

I also ran a full clean installation and environment purge locally—the entire core test suite is passing perfectly. Ready for another pass whenever you are!

@ankitsharma101 ankitsharma101 requested a review from sdirix June 8, 2026 18:42

@sdirix sdirix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Documentation: Documented the newly introduced wildcard feature, precedence tiers, and exact match priority within packages/core/README.md.

The documentation change is not part of the current PR. Please add it.

Comment thread packages/core/src/node/logger-cli-contribution.ts Outdated
@ankitsharma101 ankitsharma101 force-pushed the feature/logger-wildcard-support branch from 56f6ef5 to 577e822 Compare June 11, 2026 12:00
@ankitsharma101

Copy link
Copy Markdown
Contributor Author

Everything is updated now. I reverted the unintended changes, got the wildcard docs into the README_TEMPLATE.md and passed all CI/CD tests and fixed a bug in regex matcher. Is everything good now? Will be working on the other PR in the meantime

@sdirix sdirix changed the title feat: add wildcard and regex support for logger configuration feat: add wildcard support for logger configuration Jun 11, 2026

@sdirix sdirix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code looks good! I just have comments regarding the script, test and documentation

Comment thread examples/browser/package.json Outdated
"coverage:report": "nyc report --reporter=html",
"rebuild": "theia rebuild:browser --cacheRoot ../..",
"start": "theia start --plugins=local-dir:../../plugins --ovsx-router-config=../ovsx-router-config.json",
"start": "theia start --plugins=local-dir:../../plugins --ovsx-router-config=../ovsx-router-config.json --log-config=log-config.json",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I realized that this conflicts with the --log-level=debug of the start:debug script. I think we should introduce a new start:plugins script (with the current content of start) and then in start we do npm run -s start:plugins -- --log-config=log-config.json and in start:debug we also use start:plugins

await cli.setArguments(args);
}

it('should respect exact matches if they are evaluated last (or only)', async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Test name is misleading: this case has only an exact entry, so it never exercises the "evaluated last"

Comment thread packages/core/README.md Outdated
Comment on lines +127 to +128
"terminal": "debug",
"task": "error"
"task": "error",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Task and terminal will no longer work, so I would use wildcards for them too

Comment thread packages/core/README.md Outdated
Comment on lines +129 to +130
"ai-core:DefaultPromptFragmentCustomizationService": "debug",
"ai-core*": "error",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would change their order just to establish the generic to specialized recommendation

Suggested change
"ai-core:DefaultPromptFragmentCustomizationService": "debug",
"ai-core*": "error",
"ai-core*": "error",
"ai-core:DefaultPromptFragmentCustomizationService": "debug",

Comment thread packages/core/README_TEMPLATE.md Outdated
Comment on lines +95 to +99
"terminal": "debug",
"task": "error"
"task": "error",
"ai-core:DefaultPromptFragmentCustomizationService": "debug",
"ai-core*": "error",
"*Token*": "warn"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same comments here

…wildcard support and precedence rules to loging config and
@ankitsharma101 ankitsharma101 force-pushed the feature/logger-wildcard-support branch from 577e822 to 0a25f90 Compare June 11, 2026 21:58
@ankitsharma101

Copy link
Copy Markdown
Contributor Author

I've addresssed the script conflicts and renamed the tests. I have also updated the wildcard ocumentation as per the suggestions. Ready for the re-review.

@ankitsharma101 ankitsharma101 requested a review from sdirix June 11, 2026 22:11

@sdirix sdirix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. However I saw that we already have a regex escape util, so we should reuse that.

protected getWildcardRegex(pattern: string): RegExp {
let regex = this.wildcardRegexCache.get(pattern);
if (!regex) {
const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @ankitsharma101, I noticed that we already have a util for this:

export function escapeRegExpCharacters(value: string): string {
. It also escapes *, so you can split on the wildcard first and reuse it: pattern.split('*').map(escapeRegExpCharacters).join('.*').

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out, Stefan! I've removed the custom regex and am reusing escapeRegExpCharacters instead. Let me know if everything looks good to merge now!

@ankitsharma101 ankitsharma101 requested a review from sdirix June 15, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on author

Development

Successfully merging this pull request may close these issues.

Wildcard/Regex Support for Logger configuration

2 participants