Skip to content

Keep log level filtering when the prefix uses brackets - #19

Open
BetterAndBetterII wants to merge 1 commit into
hashicorp:masterfrom
BetterAndBetterII:fix/prefix-brackets
Open

Keep log level filtering when the prefix uses brackets#19
BetterAndBetterII wants to merge 1 commit into
hashicorp:masterfrom
BetterAndBetterII:fix/prefix-brackets

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

LevelFilter.Check treated the first [...] token on a line as the log level. When log.SetPrefix also used square brackets, that prefix was mistaken for a level name, so filtering stopped working and every message passed through.

Scan later [...] tokens and only treat a token as the level when it matches a configured Levels entry.

Test plan

  • go test -count=1 .
  • Regression for the issue repro (SetPrefix with brackets + DEBUG/WARN/ERROR)

Fixes #8

LevelFilter treated the first bracketed token as the level, so a
log.SetPrefix that also used brackets disabled filtering. Scan later
tokens and only treat a configured level as the filter level.

Fixes hashicorp#8
@BetterAndBetterII
BetterAndBetterII requested a review from a team as a code owner September 5, 2026 01:13
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.

If log.SetPrefix() contains square brackets it breaks filtering.

1 participant