Skip to content

Backport Log API enhancements and mojo MDC to 4.0.x - #12690

Draft
gnodet wants to merge 1 commit into
maven-4.0.xfrom
backport/log-api-to-maven-4.0.x
Draft

Backport Log API enhancements and mojo MDC to 4.0.x#12690
gnodet wants to merge 1 commit into
maven-4.0.xfrom
backport/log-api-to-maven-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport four Log-related improvements from master (#12572) to the 4.0.x branch for inclusion in rc-7:

  • Log.trace() — new trace level (SLF4J TRACE / JUL FINEST) to separate Maven core internals from user-facing debug messages. Currently -X floods debug output with resolver/interpolation details that drown user-relevant diagnostics.
  • Log.child(name) — creates a sub-logger with an independently filterable name (e.g. CompilerMojo.diagnostics), letting plugin sub-components log under their own namespace.
  • Logger name alignment — Maven 4 Log now uses the mojo implementation class name (e.g. org.apache.maven.plugins.compiler.CompilerMojo) instead of the goal name (compiler:compile). This matches what Maven 3 mojos already use and enables standard SLF4J hierarchical level configuration.
  • Mojo MDC propagation — sets maven.mojo.id (prefix:goal@executionId) in the SLF4J MDC during mojo execution. All log messages — including those arriving through the JUL-to-SLF4J bridge — now carry mojo context, available to any SLF4J appender via %X{maven.mojo.id}.

Also fixes a pre-existing bug where DefaultLog.warn(Supplier, Throwable) delegated to logger.info() instead of logger.warn().

Files changed

File Change
Log.java Add trace() methods + child() default method
DefaultLog.java Implement trace + child + fix warn bug
DefaultMavenPluginManager.java getFullGoalName()getImplementation()
DefaultBuildPluginManager.java getFullGoalName()getImplementation()
ProjectBuildLogAppender.java Add maven.mojo.id MDC key + setMojoId()
LoggingExecutionListener.java Set/clear mojoId MDC on mojo start/end

Test plan

  • mvn test -pl impl/maven-core passes locally
  • CI on maven-4.0.x branch

🤖 Generated with Claude Code

Backport four Log-related improvements from master to the 4.0.x branch
for inclusion in rc-7:

1. Log.trace() — new trace level (maps to SLF4J TRACE / JUL FINEST)
   to separate Maven core internals from user-facing debug messages.
   Currently -X floods debug output with resolver/interpolation details
   that drown user-relevant diagnostics.

2. Log.child(name) — creates a sub-logger with an independently
   filterable name (e.g. "CompilerMojo.diagnostics"), letting plugin
   sub-components log under their own namespace.

3. Logger name alignment — Maven 4 Log now uses the mojo implementation
   class name (e.g. "org.apache.maven.plugins.compiler.CompilerMojo")
   instead of the goal name ("compiler:compile"). This matches what
   Maven 3 mojos already use and enables standard SLF4J hierarchical
   level configuration.

4. Mojo MDC propagation — sets "maven.mojo.id" (prefix:goal@executionId)
   in the SLF4J MDC during mojo execution. All log messages — including
   those arriving through the JUL-to-SLF4J bridge — now carry mojo
   context, available to any SLF4J appender via %X{maven.mojo.id}.

Also fixes a pre-existing bug in DefaultLog where warn(Supplier, Throwable)
incorrectly delegated to logger.info() instead of logger.warn().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant