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

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


The following commit(s) were added to refs/heads/main by this push:
     new f6f99a5b75 logfile inconsistency fix, fixes #6678 (#6844)
f6f99a5b75 is described below

commit f6f99a5b75b48cffa73dc56f6681666ef17ac88f
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Fri Mar 20 19:04:18 2026 +0100

    logfile inconsistency fix, fixes #6678 (#6844)
---
 .../apache/hop/core/logging/LoggingRegistry.java   | 27 +++++++----
 .../hop/core/logging/LoggingRegistryTest.java      | 54 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 10 deletions(-)

diff --git 
a/core/src/main/java/org/apache/hop/core/logging/LoggingRegistry.java 
b/core/src/main/java/org/apache/hop/core/logging/LoggingRegistry.java
index 24ac213bd2..a910a228de 100644
--- a/core/src/main/java/org/apache/hop/core/logging/LoggingRegistry.java
+++ b/core/src/main/java/org/apache/hop/core/logging/LoggingRegistry.java
@@ -253,11 +253,23 @@ public class LoggingRegistry {
     this.fileWriterBuffers.put(fileWriterBuffer.getLogChannelId(), 
fileWriterBuffer);
   }
 
+  /**
+   * Returns the file writer buffer for {@code id} or the nearest ancestor in 
the logging parent
+   * chain (innermost match wins).
+   */
   public LogChannelFileWriterBuffer getLogChannelFileWriterBuffer(String id) {
-    for (String bufferId : this.fileWriterBuffers.keySet()) {
-      if (getLogChannelChildren(bufferId).contains(id)) {
-        return this.fileWriterBuffers.get(bufferId);
+    String currentId = id;
+    while (currentId != null) {
+      LogChannelFileWriterBuffer buffer = 
this.fileWriterBuffers.get(currentId);
+      if (buffer != null) {
+        return buffer;
+      }
+      ILoggingObject loggingObject = this.map.get(currentId);
+      if (loggingObject == null) {
+        break;
       }
+      ILoggingObject parent = loggingObject.getParent();
+      currentId = parent != null ? parent.getLogChannelId() : null;
     }
     return null;
   }
@@ -276,14 +288,9 @@ public class LoggingRegistry {
     return ids;
   }
 
+  /** Removes the buffer registered for {@code id} only (not descendant 
buffers). */
   public void removeLogChannelFileWriterBuffer(String id) {
-    Set<String> bufferIds = this.fileWriterBuffers.keySet();
-
-    for (String bufferId : bufferIds) {
-      if (getLogChannelChildren(id).contains(bufferId)) {
-        this.fileWriterBuffers.remove(bufferId);
-      }
-    }
+    this.fileWriterBuffers.remove(id);
   }
 
   public void reset() {
diff --git 
a/core/src/test/java/org/apache/hop/core/logging/LoggingRegistryTest.java 
b/core/src/test/java/org/apache/hop/core/logging/LoggingRegistryTest.java
index 7849850921..e2ceb63a83 100644
--- a/core/src/test/java/org/apache/hop/core/logging/LoggingRegistryTest.java
+++ b/core/src/test/java/org/apache/hop/core/logging/LoggingRegistryTest.java
@@ -20,7 +20,9 @@ package org.apache.hop.core.logging;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /** Unit test for {@link LoggingRegistry} */
@@ -29,6 +31,11 @@ class LoggingRegistryTest {
   public static final String LOG_CHANEL_ID_CHILD = "child-chanel-id";
   public static final String STRING_DEFAULT = "<def>";
 
+  @BeforeEach
+  void resetRegistry() {
+    LoggingRegistry.getInstance().reset();
+  }
+
   @Test
   void correctLogIdReturned_WhenLogObjectRegisteredAlready() {
     LoggingRegistry loggingRegistry = LoggingRegistry.getInstance();
@@ -85,4 +92,51 @@ class LoggingRegistryTest {
 
     assertNull(loggingRegistry.getLogChannelFileWriterBuffer(id));
   }
+
+  /**
+   * Nested workflow/pipeline actions can each specify a log file; the 
pipeline must use the
+   * innermost action's buffer, not an arbitrary ancestor match.
+   */
+  @Test
+  void nestedFileWriterBuffers_resolveInnermostAncestor() {
+    LoggingRegistry reg = LoggingRegistry.getInstance();
+
+    LoggingObject outer =
+        new LoggingObject(new SimpleLoggingObject("outer", 
LoggingObjectType.ACTION, null));
+    outer.setLogChannelId("outer-id");
+
+    LoggingObject inner =
+        new LoggingObject(new SimpleLoggingObject("inner", 
LoggingObjectType.ACTION, outer));
+    inner.setLogChannelId("inner-id");
+
+    LoggingObject pipeline =
+        new LoggingObject(new SimpleLoggingObject("pipe", 
LoggingObjectType.PIPELINE, inner));
+    pipeline.setLogChannelId("pipe-id");
+
+    reg.getMap().put("outer-id", outer);
+    reg.getMap().put("inner-id", inner);
+    reg.getMap().put("pipe-id", pipeline);
+
+    LogChannelFileWriterBuffer outerBuf = new 
LogChannelFileWriterBuffer("outer-id");
+    LogChannelFileWriterBuffer innerBuf = new 
LogChannelFileWriterBuffer("inner-id");
+    reg.registerLogChannelFileWriterBuffer(outerBuf);
+    reg.registerLogChannelFileWriterBuffer(innerBuf);
+
+    assertSame(innerBuf, reg.getLogChannelFileWriterBuffer("pipe-id"));
+  }
+
+  @Test
+  void removeLogChannelFileWriterBuffer_doesNotRemoveDescendantBuffers() {
+    LoggingRegistry reg = LoggingRegistry.getInstance();
+
+    LogChannelFileWriterBuffer outerBuf = new 
LogChannelFileWriterBuffer("outer-id");
+    LogChannelFileWriterBuffer innerBuf = new 
LogChannelFileWriterBuffer("inner-id");
+    reg.registerLogChannelFileWriterBuffer(outerBuf);
+    reg.registerLogChannelFileWriterBuffer(innerBuf);
+
+    reg.removeLogChannelFileWriterBuffer("outer-id");
+
+    assertNull(reg.getLogChannelFileWriterBuffer("outer-id"));
+    assertSame(innerBuf, reg.getLogChannelFileWriterBuffer("inner-id"));
+  }
 }

Reply via email to