Skip to content

Refactor parseLogLevel for case-insensitivity#9447

Open
Thunder420Rock wants to merge 1 commit into
iTwin:masterfrom
Thunder420Rock:patch-1
Open

Refactor parseLogLevel for case-insensitivity#9447
Thunder420Rock wants to merge 1 commit into
iTwin:masterfrom
Thunder420Rock:patch-1

Conversation

@Thunder420Rock

Copy link
Copy Markdown

Updated parseLogLevel method to be case-insensitive and return undefined for unmatched levels.fix(core-bentley): make Logger.configureLevels case-insensitive for log levels

Logger.validateProps was using isLogLevel() which called LogLevel.hasOwnProperty() to validate log level strings. This was a case-sensitive check, causing "INFO", "error", "warning" etc. to be rejected even though parseLogLevel() already handled case-insensitive matching via toUpperCase().

Fix by:

  • Updating isLogLevel() to delegate to parseLogLevel() instead of hasOwnProperty()
  • Updating parseLogLevel() to return undefined for unrecognized strings (instead of falling back to LogLevel.None), and adding "NONE" as an explicit valid case
  • Updating configureLevels() to guard against undefined from parseLogLevel()

Fixes #8476

Updated parseLogLevel method to be case-insensitive and return undefined for unmatched levels.fix(core-bentley): make Logger.configureLevels case-insensitive for log levels

Logger.validateProps was using isLogLevel() which called LogLevel.hasOwnProperty()
to validate log level strings. This was a case-sensitive check, causing "INFO",
"error", "warning" etc. to be rejected even though parseLogLevel() already handled
case-insensitive matching via toUpperCase().

Fix by:
- Updating isLogLevel() to delegate to parseLogLevel() instead of hasOwnProperty()
- Updating parseLogLevel() to return undefined for unrecognized strings (instead
  of falling back to LogLevel.None), and adding "NONE" as an explicit valid case
- Updating configureLevels() to guard against undefined from parseLogLevel()

Fixes iTwin#8476
@Thunder420Rock
Thunder420Rock requested a review from a team as a code owner June 26, 2026 14:52
@hl662

hl662 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

H!, can you follow https://github.com/iTwin/itwinjs-core?tab=contributing-ov-file#source-code-edit-workflow

There are files I expect to see in this PR that aren't yet, and we'll be open to reviewing and approving workflows after thats done

@anmolshres98

Copy link
Copy Markdown
Contributor

Thanks for the contribution!

The issue is this changes parseLogLevel()'s return type from LogLevel to LogLevel | undefined. Logger is @public so its members are public api, which makes this a breaking change.

The actual bug is just in isLogLevel() though, so could you keep the fix scoped to that and leave parseLogLevel() as-is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logger.configureLevels does not handle log levels case-insensitive

3 participants