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

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 30ffc12b5 pass slf4j context to spawned thread (#3241)
30ffc12b5 is described below

commit 30ffc12b5bf5ddf68886242d146dd568b1bcda0a
Author: Scott Williams <[email protected]>
AuthorDate: Wed Feb 4 01:23:26 2026 +0000

    pass slf4j context to spawned thread (#3241)
    
    Co-authored-by: Scott Williams <[email protected]>
---
 .../surefire/booterclient/output/ThreadedStreamConsumer.java | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
index 7e1cdc5e2..d9abe465d 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
@@ -22,6 +22,7 @@
 
 import java.io.Closeable;
 import java.io.IOException;
+import java.util.Map;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -29,6 +30,7 @@
 
 import org.apache.maven.surefire.api.event.Event;
 import org.apache.maven.surefire.extensions.EventHandler;
+import org.slf4j.MDC;
 
 import static java.lang.Thread.currentThread;
 import static 
org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThread;
@@ -57,9 +59,11 @@ final class Pumper implements Runnable {
         private final EventHandler<Event> target;
 
         private final MultipleFailureException errors = new 
MultipleFailureException();
+        private final Map<String, String> parentThreadsMdcContextMap;
 
-        Pumper(EventHandler<Event> target) {
+        Pumper(EventHandler<Event> target, Map<String, String> mdcContextMap) {
             this.target = target;
+            this.parentThreadsMdcContextMap = mdcContextMap;
         }
 
         /**
@@ -75,6 +79,10 @@ final class Pumper implements Runnable {
          */
         @Override
         public void run() {
+            // copy mdc context map from parent thread so that mvn
+            // tools that build in parallel can use it in there logging
+            // to make clear what module is producing the logs
+            MDC.setContextMap(parentThreadsMdcContextMap);
             while (!stop.get() || !synchronizer.isEmptyQueue()) {
                 try {
                     Event item = synchronizer.awaitNext();
@@ -104,7 +112,7 @@ void throwErrors() throws IOException {
     }
 
     public ThreadedStreamConsumer(EventHandler<Event> target) {
-        pumper = new Pumper(target);
+        pumper = new Pumper(target, MDC.getCopyOfContextMap());
         Thread consumer = newDaemonThread(pumper, "ThreadedStreamConsumer");
         consumer.setUncaughtExceptionHandler((t, e) -> isAlive.set(false));
         consumer.start();

Reply via email to