Skip to content

Commit

Permalink
Only prefix program output with thread name when Maven is running wit…
Browse files Browse the repository at this point in the history
…h multiple threads. (#157)
  • Loading branch information
hankolerd authored Nov 10, 2023
1 parent 584c544 commit 6fcb15b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ else if ( !StringUtils.isEmpty( argsProp ) )
else if (useMavenLogger)
{
getLog().debug("Will redirect program output to Maven logger");
final String parentThreadName = Thread.currentThread().getName();
final String logSuffix = "[" + parentThreadName + "] ";
// If running parallel, append the projects original (i.e. current) thread name to the program
// output as a log prefix, to enable easy tracing of program output when intermixed with other
// Maven log output. NOTE: The accept(..) methods are running in PumpStreamHandler thread,
// which is why we capture the thread name prefix here.
final String logPrefix = session.isParallel() ? "[" + Thread.currentThread().getName() + "] " : "";
Consumer<String> mavenOutRedirect = new Consumer<String>()
{

Expand All @@ -462,11 +465,11 @@ public void accept(String logMessage)
{
if (quietLogs)
{
getLog().debug(logSuffix + logMessage);
getLog().debug(logPrefix + logMessage);
}
else
{
getLog().info(logSuffix + logMessage);
getLog().info(logPrefix + logMessage);
}
}
};
Expand All @@ -476,7 +479,7 @@ public void accept(String logMessage)
@Override
public void accept(String logMessage)
{
getLog().error(logSuffix + logMessage);
getLog().error(logPrefix + logMessage);
}
};

Expand Down

0 comments on commit 6fcb15b

Please sign in to comment.