sharanggupta opened a new issue, #4418:
URL: https://github.com/apache/logging-log4j2/issues/4418

   
   ## Description
   
   `Configurator.setAllLevels(parentLogger, level)` is documented as setting 
the level of `parentLogger` "and all 'child' loggers". It selects the child 
`LoggerConfig`s with a plain `String.startsWith` (`Configurator.java` line 325 
on `2.x`):
   
   ```java
   for (final Map.Entry<String, LoggerConfig> entry : 
config.getLoggers().entrySet()) {
       if (entry.getKey().startsWith(parentLogger)) {
           set |= setLevel(entry.getValue(), level);
       }
   }
   ```
   
   so a sibling logger whose name merely starts with the same characters is 
changed too. With explicit `LoggerConfig`s for `com.foo`, `com.foo.child`, 
`com.foobar` and `com.foobar.child` (all `INFO`), 
`Configurator.setAllLevels("com.foo", Level.TRACE)` gives:
   
   ```
   com.foo            -> TRACE (expected)
   com.foo.child      -> TRACE (expected)
   com.foobar         -> TRACE (sibling, unexpected)
   com.foobar.child   -> TRACE (sibling, unexpected)
   com.fo             -> INFO
   ```
   
   (reproduced with `log4j-core` 2.26.1; the same lines exist on `main`). 
Everywhere else the logger hierarchy is dot-delimited — 
`AbstractConfiguration.getLoggerConfig()` walks `lastIndexOf('.')`, and 
#4412/#4414 recently fixed the identical `startsWith` in 
`LoggerNameLevelRewritePolicy` — and the method was originally named 
`setChildren()`. Any two packages that share a textual prefix (`org.app.db` / 
`org.app.dbmigration`) hit this with ordinary configuration.
   
   ## Configuration
   Version: 2.26.1 (and `2.x`/`main` heads). Operating system / JDK: any.
   
   ## Proposed fix
   Match only `parentLogger` itself and names continuing with a `.` (root `""` 
and a trailing-dot parent keep matching everything below them, as in #4414), 
plus a regression test in `LoggerTest` with a sibling logger. I have the branch 
ready.
   
   


-- 
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]

Reply via email to