ramanathan1504 commented on code in PR #4419:
URL: https://github.com/apache/logging-log4j2/pull/4419#discussion_r4358370443
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java:
##########
@@ -215,6 +215,18 @@ void debugChangeLevelAllChildrenLoggers() {
assertEventCount(app.getEvents(), 5);
}
+ @Test
+ void setAllLevelsDoesNotChangeSiblingLoggers() {
+ // A logger whose name merely starts with the parent's name is a
sibling, not a child, in the
+ // dot-separated hierarchy and must keep its own level
+ final String sibling = logger.getName() + "Sibling";
+ Configurator.setLevel(sibling, Level.INFO);
Review Comment:
Give the child its own `LoggerConfig`. Without it the child inherits `OFF`
from the parent, and removing the `charAt(...) == '.'` check keeps the test
green.
```suggestion
Configurator.setLevel(loggerChild.getName(), Level.INFO);
Configurator.setLevel(sibling, Level.INFO);
```
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java:
##########
@@ -215,6 +215,18 @@ void debugChangeLevelAllChildrenLoggers() {
assertEventCount(app.getEvents(), 5);
}
+ @Test
+ void setAllLevelsDoesNotChangeSiblingLoggers() {
+ // A logger whose name merely starts with the parent's name is a
sibling, not a child, in the
+ // dot-separated hierarchy and must keep its own level
+ final String sibling = logger.getName() + "Sibling";
+ Configurator.setLevel(sibling, Level.INFO);
+ Configurator.setAllLevels(logger.getName(), Level.OFF);
+ assertEquals(Level.OFF, logger.getLevel());
+ assertEquals(Level.OFF, loggerChild.getLevel());
+ assertEquals(Level.INFO, LogManager.getLogger(sibling).getLevel(),
"sibling logger must keep its level");
+ }
Review Comment:
The root and trailing-dot parents have no test. Removing `isEmpty()` or
`endsWith(".")` from `isChildLogger` keeps every test green.
```suggestion
}
@Test
void setAllLevelsWithRootOrTrailingDotChangesDescendants() {
Configurator.setLevel(loggerChild.getName(), Level.INFO);
Configurator.setAllLevels(logger.getName() + ".", Level.WARN);
assertEquals(Level.WARN, loggerChild.getLevel());
Configurator.setAllLevels("", Level.ERROR);
assertEquals(Level.ERROR, loggerChild.getLevel());
}
```
--
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]