sharanggupta opened a new issue, #4412:
URL: https://github.com/apache/logging-log4j2/issues/4412
**Describe the bug**
`LoggerNameLevelRewritePolicy.rewrite()` matches the configured logger name
with `String.startsWith`, with no check for a following `.` or exact-match
boundary. A policy configured for `logger="com.foo"` therefore also matches an
unrelated sibling package such as `com.foobar.Baz`, which merely happens to
share the same character prefix without being a sub-logger of `com.foo` at all.
This is inconsistent with how every other logger-name-hierarchy feature in
Log4j works (e.g. `<Logger name="com.foo">` resolves by progressively
truncating at the last dot, never by substring prefix matching), and it's a
silent effect: a `WARN` (or any configured level) from the unrelated package
gets rewritten/demoted with no error, warning, or indication anything
unexpected happened.
**Environment**
- Log4j version: 2.26.1 (latest stable; also reproduces on `2.x`/3.0.0-beta3
source)
- OS: macOS (environment-independent; pure string logic)
- JDK: 17
**To Reproduce**
```java
KeyValuePair[] rewrite = { new KeyValuePair("WARN", "DEBUG") };
LoggerNameLevelRewritePolicy policy =
LoggerNameLevelRewritePolicy.createPolicy("com.foo", rewrite);
LogEvent event = Log4jLogEvent.newBuilder()
.setLoggerName("com.foobar.PaymentProcessor")
.setLevel(Level.WARN)
.setMessage(new SimpleMessage("payment declined"))
.build();
LogEvent rewritten = policy.rewrite(event);
// rewritten.getLevel() is DEBUG, even though "com.foobar.PaymentProcessor"
is not
// a descendant of "com.foo" — it's an unrelated sibling package.
```
**Expected behavior**
A rule configured for `"com.foo"` should only affect `"com.foo"` itself and
its true descendants (`"com.foo.Bar"`, etc.), not an unrelated package that
happens to share the same character prefix.
**Additional context**
I have a fix + regression test ready and will open a PR referencing this
issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]