ramanathan1504 commented on code in PR #4414:
URL: https://github.com/apache/logging-log4j2/pull/4414#discussion_r4330187452


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/LoggerNameLevelRewritePolicy.java:
##########
@@ -92,4 +92,19 @@ public LogEvent rewrite(final LogEvent event) {
                 new Log4jLogEvent.Builder(event).setLevel(newLevel).build();
         return result;
     }
+
+    /**
+     * Matches {@code eventLoggerName} against the configured {@link 
#loggerName} the same way the rest of
+     * Log4j treats logger-name hierarchy: either an exact match, or a true 
descendant separated by a '.'.
+     * A plain {@code startsWith} check would also match an unrelated sibling 
package that merely shares the
+     * same character prefix, e.g. a policy for {@code "com.foo"} would 
incorrectly also match
+     * {@code "com.foobar.Baz"}.
+     */
+    private boolean matchesLoggerNameOrDescendant(final String 
eventLoggerName) {
+        if (eventLoggerName == null || 
!eventLoggerName.startsWith(loggerName)) {
+            return false;
+        }
+        return eventLoggerName.length() == loggerName.length()
+                || eventLoggerName.charAt(loggerName.length()) == '.';

Review Comment:
   A configured name that is empty or ends with `.` already sits on a boundary.
   
   ```suggestion
           return eventLoggerName.length() == loggerName.length()
                   || loggerName.isEmpty()
                   || loggerName.endsWith(".")
                   || eventLoggerName.charAt(loggerName.length()) == '.';
   ```



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