This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 67b1e486614 NIFI-16602 Add LogFileSuffixFilter to per Process Group 
logging appender (#11940)
67b1e486614 is described below

commit 67b1e486614d49ad9540d6aa1d79e9d14a77748f
Author: Vincenzo Lombardo <[email protected]>
AuthorDate: Wed Nov 18 18:50:29 2026 +0100

    NIFI-16602 Add LogFileSuffixFilter to per Process Group logging appender 
(#11940)
    
    - Added LogFileSuffixFilter denying events without the logFileSuffix
      key/value pair, so that NifiDiscriminator no longer throws a
      NullPointerException for every log event without key/value pairs
    - Added the filter to the DEDICATED_LOGGING appender in logback.xml
    - NifiDiscriminator semantics unchanged to remain compatible with
      existing logback.xml files that do not reference the filter
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
    Signed-off-by: David Handermann <[email protected]>
---
 .../apache/nifi/logging/LogFileSuffixFilter.java   | 49 ++++++++++++++
 .../nifi/logging/LogFileSuffixFilterTest.java      | 77 ++++++++++++++++++++++
 .../src/main/resources/conf/logback.xml            |  2 +
 3 files changed, 128 insertions(+)

diff --git 
a/nifi-commons/nifi-per-process-group-logging/src/main/java/org/apache/nifi/logging/LogFileSuffixFilter.java
 
b/nifi-commons/nifi-per-process-group-logging/src/main/java/org/apache/nifi/logging/LogFileSuffixFilter.java
new file mode 100644
index 00000000000..e3979d33b6c
--- /dev/null
+++ 
b/nifi-commons/nifi-per-process-group-logging/src/main/java/org/apache/nifi/logging/LogFileSuffixFilter.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.logging;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.spi.FilterReply;
+import org.slf4j.event.KeyValuePair;
+
+import java.util.List;
+
+/**
+ * Filter for the per Process Group logging appender that denies events 
without the log file suffix key/value pair,
+ * so that only component log messages of Process Groups defining a Log File 
Suffix reach the {@link NifiDiscriminator}
+ */
+public class LogFileSuffixFilter extends Filter<ILoggingEvent> {
+    private static final String KEY = "logFileSuffix";
+
+    @Override
+    public FilterReply decide(final ILoggingEvent event) {
+        if (!isStarted()) {
+            return FilterReply.NEUTRAL;
+        }
+
+        final List<KeyValuePair> keyValuePairs = event.getKeyValuePairs();
+        if (keyValuePairs != null) {
+            for (final KeyValuePair keyValuePair : keyValuePairs) {
+                if (KEY.equals(keyValuePair.key)) {
+                    return FilterReply.NEUTRAL;
+                }
+            }
+        }
+        return FilterReply.DENY;
+    }
+}
diff --git 
a/nifi-commons/nifi-per-process-group-logging/src/test/java/org/apache/nifi/logging/LogFileSuffixFilterTest.java
 
b/nifi-commons/nifi-per-process-group-logging/src/test/java/org/apache/nifi/logging/LogFileSuffixFilterTest.java
new file mode 100644
index 00000000000..99799c7a0a6
--- /dev/null
+++ 
b/nifi-commons/nifi-per-process-group-logging/src/test/java/org/apache/nifi/logging/LogFileSuffixFilterTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.logging;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.spi.FilterReply;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.event.KeyValuePair;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class LogFileSuffixFilterTest {
+    private static final String LOG_FILE_SUFFIX_KEY = "logFileSuffix";
+
+    private LogFileSuffixFilter filter;
+
+    @BeforeEach
+    void setFilter() {
+        filter = new LogFileSuffixFilter();
+        filter.start();
+    }
+
+    @Test
+    void testDecideKeyValuePairsNull() {
+        final LoggingEvent event = new LoggingEvent();
+
+        assertEquals(FilterReply.DENY, filter.decide(event));
+    }
+
+    @Test
+    void testDecideKeyValuePairsEmpty() {
+        final LoggingEvent event = new LoggingEvent();
+        event.setKeyValuePairs(List.of());
+
+        assertEquals(FilterReply.DENY, filter.decide(event));
+    }
+
+    @Test
+    void testDecideKeyValuePairsWithoutSuffix() {
+        final LoggingEvent event = new LoggingEvent();
+        event.setKeyValuePairs(List.of(new KeyValuePair("other", "value")));
+
+        assertEquals(FilterReply.DENY, filter.decide(event));
+    }
+
+    @Test
+    void testDecideKeyValuePairsWithSuffix() {
+        final LoggingEvent event = new LoggingEvent();
+        event.setKeyValuePairs(List.of(new KeyValuePair("other", "value"), new 
KeyValuePair(LOG_FILE_SUFFIX_KEY, "suffix")));
+
+        assertEquals(FilterReply.NEUTRAL, filter.decide(event));
+    }
+
+    @Test
+    void testDecideNotStarted() {
+        filter.stop();
+
+        assertEquals(FilterReply.NEUTRAL, filter.decide(new LoggingEvent()));
+    }
+}
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml
 
b/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml
index 1ed2bef1b69..e29363fab34 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml
@@ -123,6 +123,8 @@
     </appender>
 
     <appender name="DEDICATED_LOGGING" 
class="ch.qos.logback.classic.sift.SiftingAppender">
+        <!-- Denies events without a Log File Suffix before they reach the 
discriminator -->
+        <filter class="org.apache.nifi.logging.LogFileSuffixFilter"/>
         <discriminator class="org.apache.nifi.logging.NifiDiscriminator"/>
         <sift>
             <appender name="APP-${logFileSuffix}_FILE" 
class="ch.qos.logback.core.rolling.RollingFileAppender">

Reply via email to