QPID-8423: [Broker-J] Fix filtering of log events produced by loggers with name exactly equals to rule logger name
diff --git a/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilter.java b/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilter.java
index a2c620a..68d05f6 100644
--- a/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilter.java
+++ b/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilter.java
@@ -70,7 +70,7 @@
                 @Override
                 public FilterReply decide(final ILoggingEvent event)
                 {
-                    return getFilterReply(event.getLevel());
+                    return getWildCardLoggerFilterReply(event.getLevel());
                 }
             };
         }
@@ -84,7 +84,7 @@
                 {
                     if (event.getLoggerName().startsWith(prefixName))
                     {
-                        return getFilterReply(event.getLevel());
+                        return getWildCardLoggerFilterReply(event.getLevel());
                     }
                     return FilterReply.NEUTRAL;
                 }
@@ -99,7 +99,7 @@
                 {
                     if (event.getLoggerName().equals(loggerName))
                     {
-                        return getFilterReply(event.getLevel());
+                        return getExactLoggerFilterReply(event.getLevel());
                     }
                     return FilterReply.NEUTRAL;
                 }
@@ -107,13 +107,9 @@
         }
     }
 
-    private FilterReply getFilterReply(final Level eventLevel)
+    private FilterReply getWildCardLoggerFilterReply(final Level eventLevel)
     {
-        if (_level == Level.OFF)
-        {
-            return FilterReply.DENY;
-        }
-        else if (eventLevel.isGreaterOrEqual(_level))
+        if (eventLevel.isGreaterOrEqual(_level))
         {
             return FilterReply.ACCEPT;
         }
@@ -123,6 +119,11 @@
         }
     }
 
+    private FilterReply getExactLoggerFilterReply(final Level eventLevel)
+    {
+        return  eventLevel.isGreaterOrEqual(_level) ? FilterReply.ACCEPT : FilterReply.DENY;
+    }
+
     @Override
     public Level getEffectiveLevel(final Logger logger)
     {
diff --git a/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/BrokerLoggerTest.java b/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/BrokerLoggerTest.java
index 57dedd9..895c312 100644
--- a/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/BrokerLoggerTest.java
+++ b/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/BrokerLoggerTest.java
@@ -271,6 +271,33 @@
         assertLoggedEvent(_loggerAppender, true, "foo message", fooLogger.getName(), Level.WARN);
     }
 
+    @Test
+    public void testExactLoggerRuleSupersedeWildCardLoggerRule()
+    {
+        Map<String, Object> fooRuleAttributes =
+                createBrokerNameAndLevelLogInclusionRuleAttributes("fooRule",
+                                                                   "org.apache.qpid.foo.*",
+                                                                   LogLevel.INFO);
+        Map<String, Object> barRuleAttributes =
+                createBrokerNameAndLevelLogInclusionRuleAttributes("barRule",
+                                                                   "org.apache.qpid.foo.bar",
+                                                                   LogLevel.WARN);
+
+        _brokerLogger.createChild(BrokerLogInclusionRule.class, fooRuleAttributes);
+        _brokerLogger.createChild(BrokerLogInclusionRule.class, barRuleAttributes);
+
+        Logger barLogger = LoggerFactory.getLogger("org.apache.qpid.foo.bar");
+        barLogger.info("info bar message");
+        barLogger.error("error bar message");
+
+        Logger fooLogger = LoggerFactory.getLogger("org.apache.qpid.foo.foo");
+        fooLogger.info("info foo message");
+
+        assertLoggedEvent(_loggerAppender, false, "info bar message", barLogger.getName(), Level.INFO);
+        assertLoggedEvent(_loggerAppender, true, "error bar message", barLogger.getName(), Level.ERROR);
+        assertLoggedEvent(_loggerAppender, true, "info foo message", fooLogger.getName(), Level.INFO);
+    }
+
     private Map<String, Object> createBrokerNameAndLevelLogInclusionRuleAttributes(final String loggerName,
                                                                                    final LogLevel logLevel)
     {
diff --git a/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilterTest.java b/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilterTest.java
index fb6ceab..1e02735 100644
--- a/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilterTest.java
+++ b/broker-plugins/logging-logback/src/test/java/org/apache/qpid/server/logging/logback/LoggerNameAndLevelFilterTest.java
@@ -142,7 +142,7 @@
         when(event.getLevel()).thenReturn(Level.DEBUG);
         when(event.getLoggerName()).thenReturn("org.apache.qpid");
         assertEquals("Unexpected reply for non matching log leve and same logger namel",
-                            FilterReply.NEUTRAL,
+                            FilterReply.DENY,
                             filter.decide(event));
     }