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

Conversation

hankolerd
Copy link
Contributor

@hankolerd hankolerd commented Jun 18, 2020

This is a follow-up to some review comments in Pull Request #153 (for Issue #152) after it had been merged.

Attaching the owning thread name to program output as a prefix will only occur if the Maven session is running with 2 or more threads (i.e. session.isParallel()). Otherwise no log prefix is attached.

Examples
Below is sample output of two modules in a reactor with the following plugin execution configured:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.1-SNAPSHOT</version>
  <executions>
    <execution>
      <id>test</id>
      <phase>compile</phase>
      <goals>
        <goal>exec</goal>
      </goals>
      <configuration>
        <executable>bash</executable>
        <arguments>
          <argument>-c</argument>
          <argument><![CDATA[
            for i in {1..100}
            do
              echo "${project.artifactId} - $i"
            done
          ]]></argument>
        </arguments>
      </configuration>
    </execution>
  </executions>
</plugin>

Example 1. Default behavior, single-thread: mvn clean install

module1 - 56
module1 - 57
...
module2 - 61
module2 - 62
...

Example 2. Default behavior, multi-thread: mvn clean install -T 2

...
module1 - 53
2m o-d u8l0e
module2 - 81
module2 - 812
 m-o d5u4l
module1 - 55
...

Example 3. With Maven Logger option enabled, single-thread: mvn clean install -Dexec.useMavenLogger=true

13:22:22.491 [Exec Stream Pumper] [INFO] module1 - 56
13:22:22.492 [Exec Stream Pumper] [INFO] module1 - 57
...
13:22:22.692 [Exec Stream Pumper] [INFO] module2 - 61
13:22:22.692 [Exec Stream Pumper] [INFO] module2 - 62

Example 4. With Maven Logger option enabled, multi-thread: mvn clean install -T 2 -Dexec.useMavenLogger=true

...
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 1] module1 - 53
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 2] module2 - 58
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 1] module1 - 54
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 2] module2 - 59
...

NOTE: In these last 2 examples, My Maven installation is configured to always print timestamp and thread name before Maven log output.

…en Maven is running with multiple threads.
Copy link

@mirabilos mirabilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! (I can only test this when I figure out how to use a snapshot…)

@olamy
Copy link
Member

olamy commented Jul 12, 2022

interesting! happy to merge. do you mind resolving conflicts?

@slawekjaranowski slawekjaranowski merged commit 6fcb15b into mojohaus:master Nov 10, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants