sharanggupta commented on code in PR #4419:
URL: https://github.com/apache/logging-log4j2/pull/4419#discussion_r4361122641


##########
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:
   Done in 05f9b0fb58: the child now gets its own level before the call, so the 
assertion checks the child's own `LoggerConfig` rather than inheritance. With 
the `charAt(...) == '.'` check removed this test now fails (verified).



##########
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:
   Added as suggested in 05f9b0fb58. Removing `isEmpty()` or `endsWith(".")` 
from `isChildLogger` fails it (`expected: <ERROR> but was: <WARN>` for the root 
case); verified both.



##########
src/changelog/.2.x.x/4418_Configurator-setAllLevels-boundary.xml:
##########
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+           https://logging.apache.org/xml/ns
+           https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+    <issue id="4418" 
link="https://github.com/apache/logging-log4j2/issues/4418"/>
+    <description format="asciidoc">
+        Fix `Configurator.setAllLevels()` also changing the level of sibling 
loggers that only share a character prefix with the given parent logger name, 
instead of only its descendants.

Review Comment:
   Shortened to the suggested line in 05f9b0fb58.



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