Forward-port: Log API enhancements and mojo MDC - #12929
Merged
Merged
Conversation
* Backport Log API enhancements and mojo MDC to 4.0.x
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 <[email protected]>
* Add isXxxEnabled() guards to Throwable-only log overloads
Align with master by wrapping the five xxx(Throwable) overloads
in level-enabled checks, avoiding unnecessary method calls and
empty string construction when the level is disabled.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* Address review: default trace methods and fork-aware mojoId
Apply review fixes from #12694 to align the backport:
- Log.java: make all 6 trace methods default (no-ops) to prevent
AbstractMethodError for existing third-party Log implementors.
isTraceEnabled() returns false by default.
- ProjectBuildLogAppender: add FORKING_MOJO_ID ThreadLocal mirroring
the existing FORKING_PROJECT_ID pattern. When setMojoId(null) is
called, the forking mojo's ID is restored instead of clearing.
- LoggingExecutionListener: save current mojoId in forkStarted(),
clear forking mojoId in forkSucceeded/forkFailed. Fix cleanup
ordering in mojoSucceeded/mojoFailed — delegate runs first, then
MDC is cleared.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* Address review: add DefaultLogTest and clear MDC on mojoSkipped
- Add DefaultLogTest with 5 tests: warn/supplier regression,
trace delegation, trace no-op guard, child() sub-logger,
and default trace methods (AbstractMethodError prevention).
- Clear mojo MDC in mojoSkipped() to prevent stale mojo context
from leaking into subsequent log messages.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---------
Co-authored-by: Claude Opus 4.6 <[email protected]>
5 tasks
gnodet
commented
Aug 30, 2026
Contributor
Author
There was a problem hiding this comment.
Clean forward-port of #12690 from maven-4.0.x to master. The diff is byte-identical to the merged PR — no adaptation was needed. All findings from 4 prior review rounds on #12690 have been addressed.
Observations (informational):
- Cherry-pick applied with zero conflicts; both diffs are 617 lines and byte-identical
- Other
Logimplementations on master (MojoLogWrapper, compatDefaultLog,SystemStreamLog) implement the legacyorg.apache.maven.plugin.logging.Log, notorg.apache.maven.api.plugin.Log, so they are unaffected by the newtrace/childdefault methods - The
getFullGoalName()→getImplementation()change is consistent with existing usage inDefaultMavenPluginManager.javawhich already usesgetImplementation()for the mojo logger - PR description accurately documents the relationship with #12694 which will add master-only additions
📋 PR Metadata
| Aspect | Current | Suggested |
|---|---|---|
| Labels | (none) | enhancement |
| Milestone | (none) | 4.1.0 |
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
elharo
reviewed
Aug 30, 2026
| } | ||
|
|
||
| /** | ||
| * Sends a message to the user in the <b>trace</b> error level. |
Contributor
There was a problem hiding this comment.
usually written as "at the trace error level" rather than "in the trace error level"
| * such as resolver negotiation, model interpolation, and lifecycle | ||
| * ordering details. Use {@link #debug(CharSequence)} instead for | ||
| * messages that help <em>users</em> investigate their build | ||
| * (e.g. why a module was recompiled). |
- "in the trace error level" → "at the trace error level" - "e.g." → "for instance," Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@gnodet Please assign appropriate label to PR according to the type of change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward-port of #12690 (merged into
maven-4.0.x) tomaster.Brings the following Log API enhancements to master:
Log.trace()— new trace level (SLF4J TRACE) withdefaultno-op implementations to preventAbstractMethodErrorfor existing third-partyLogimplementorsLog.child(name)— creates a sub-logger with an independently filterable hierarchical namemaven.mojo.idin SLF4J MDC during mojo execution, fork-aware (saves/restores across forked lifecycles)DefaultLog.warn(Supplier, Throwable)was delegating tologger.info()instead oflogger.warn()isXxxEnabled()guards — added toThrowable-only log overloadsDefaultLogTest— 5 new tests covering trace delegation, warn bug fix, child loggers, and backward compatibilityOnce this merges, #12694 will be rebased on top to layer the master-only additions (structured
LogEvent, JUL handler,LogSink,withMetadata/StackWalker).Related
maven-4.0.x, milestone 4.1.0)Test plan
🤖 Generated with Claude Code