Skip to content

Commit 6fcb15b

Browse files
authored
Only prefix program output with thread name when Maven is running with multiple threads. (#157)
1 parent 584c544 commit 6fcb15b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/org/codehaus/mojo/exec/ExecMojo.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,11 @@ else if ( !StringUtils.isEmpty( argsProp ) )
452452
else if (useMavenLogger)
453453
{
454454
getLog().debug("Will redirect program output to Maven logger");
455-
final String parentThreadName = Thread.currentThread().getName();
456-
final String logSuffix = "[" + parentThreadName + "] ";
455+
// If running parallel, append the projects original (i.e. current) thread name to the program
456+
// output as a log prefix, to enable easy tracing of program output when intermixed with other
457+
// Maven log output. NOTE: The accept(..) methods are running in PumpStreamHandler thread,
458+
// which is why we capture the thread name prefix here.
459+
final String logPrefix = session.isParallel() ? "[" + Thread.currentThread().getName() + "] " : "";
457460
Consumer<String> mavenOutRedirect = new Consumer<String>()
458461
{
459462

@@ -462,11 +465,11 @@ public void accept(String logMessage)
462465
{
463466
if (quietLogs)
464467
{
465-
getLog().debug(logSuffix + logMessage);
468+
getLog().debug(logPrefix + logMessage);
466469
}
467470
else
468471
{
469-
getLog().info(logSuffix + logMessage);
472+
getLog().info(logPrefix + logMessage);
470473
}
471474
}
472475
};
@@ -476,7 +479,7 @@ public void accept(String logMessage)
476479
@Override
477480
public void accept(String logMessage)
478481
{
479-
getLog().error(logSuffix + logMessage);
482+
getLog().error(logPrefix + logMessage);
480483
}
481484
};
482485

0 commit comments

Comments
 (0)