Skip to content

Pass slf4j context to spawned thread#3241

Merged
olamy merged 1 commit intoapache:masterfrom
scottrw93:master
Feb 4, 2026
Merged

Pass slf4j context to spawned thread#3241
olamy merged 1 commit intoapache:masterfrom
scottrw93:master

Conversation

@scottrw93
Copy link
Contributor

@scottrw93 scottrw93 commented Jan 15, 2026

Details

Resolves #2687

Now you have moved to slf4j it would be nice to pass the slf4j mdc context from the parent thread to the threads created by ThreadedStreamConsumer. The context is really useful for custom logging implementations in maven as when running in parallel mode it lets you do things like prefix the log line with the module name that generated it or grouping all logs by the module and printing them sequentially at the end of the build.

The best example of this is in mvnd where they prefix each log line with the module, but it doesn't work for surefire as the logging context is logged in the new thread. If multiple modules are running test at once its not clear which one generated the log line.

[maven-artifact] [INFO]
[maven-artifact] [INFO] -------------------------------------------------------
[maven-artifact] [INFO]  T E S T S
[maven-artifact] [INFO] -------------------------------------------------------
[maven-slf4j-provider] [INFO] Enabled default license matchers.
[maven-slf4j-provider] [INFO] Will parse SCM ignores for exclusions...
[maven-slf4j-provider] [INFO] Finished adding exclusions from SCM ignore files.
[maven-slf4j-provider] [INFO] 62 implicit excludes (use -debug for more details).
[maven-slf4j-provider] [INFO] 18 explicit excludes (use -debug for more details).
[maven-slf4j-provider] [INFO] 7 resources included (use -debug for more details)
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 s - in org.apache.maven.model.CiManagementTest
[INFO] Running org.apache.maven.model.ReportingTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.035 s - in org.apache.maven.model.ReportingTest
[INFO] Running org.apache.maven.model.ScmTest

Checklist

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@scottrw93
Copy link
Contributor Author

Anyone able to take a look at this?

@scottrw93
Copy link
Contributor Author

I cleaned up the imports that caused spotless checks to fail.

@scottrw93
Copy link
Contributor Author

All the checks have passed, does this look ok to merge?

@olamy olamy merged commit 30ffc12 into apache:master Feb 4, 2026
14 checks passed
@github-actions
Copy link

github-actions bot commented Feb 4, 2026

@olamy Please assign appropriate label to PR according to the type of change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SUREFIRE-2204] Convert logging to slf4j to allow MDC to be printed

2 participants