Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only prefix program output with thread name when running with multiple threads #157

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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