GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Log API enhancements and mojo MDC by gnodet · Pull Request #12690 · apache/maven Conversation
|
| File | Change |
|---|---|
Log.java |
Add trace() default methods + child() default method |
DefaultLog.java |
Implement trace + child + fix warn bug + isXxxEnabled guards |
DefaultMavenPluginManager.java |
getFullGoalName() → getImplementation() |
DefaultBuildPluginManager.java |
getFullGoalName() → getImplementation() |
ProjectBuildLogAppender.java |
Add maven.mojo.id MDC key + fork-aware setMojoId() / setForkingMojoId() |
LoggingExecutionListener.java |
Set/clear mojoId MDC on mojo start/end, save/restore across forks |
mvn test -pl impl/maven-core — 562 tests pass🤖 Generated with Claude Code
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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]>
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]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Clean, well-scoped backport of Log API enhancements from #12572 to 4.0.x. All functional changes are correct, the bug fix (warn(Supplier, Throwable) delegating to logger.info() instead of logger.warn()) is verified, and the backport includes additional consistency improvements.
Notable observations:
@since tags that the original PR uses (4.1.0 for trace methods). Since the Log interface is @since 4.0.0 and the 4.0.x branch has no per-method @since tags, this is the right call.isXxxEnabled() guards to the existing debug(Throwable), info(Throwable), warn(Throwable), and error(Throwable) methods, which previously called the logger unconditionally. This is a welcome consistency fix not in the original PR.Log interface is @Provider and @Experimental, so adding new abstract methods (trace methods) is safe — external implementations are not expected.Minor items:
DefaultLogTest.java with a test for child(). This test was not included in the backport — consider adding it for parity.mojoSkipped() does not clear the mojo MDC. If a previous mojo set the MDC and a subsequent mojo is skipped, log messages during mojoSkipped handling would carry the stale mojo ID. This matches the original PR behavior and is a very minor edge case.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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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]>
|
Applied review fixes from #12694 to align the backport: 1. 2. 3.
Build: compiles cleanly and passes all maven-core tests (562 tests, 2 pre-existing failures unrelated to logging). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Delta review — checking the latest commit e3c872f5 ("Address review: default trace methods and fork-aware mojoId").
The latest commit correctly addresses two important concerns:
Default trace methods in Log.java — Essential for this backport. On 4.0.x, existing third-party Log implementations would get AbstractMethodError if these were abstract. The no-op defaults (isTraceEnabled returns false, all trace overloads are no-ops) are the correct backward-compatible choice.
Fork-aware mojoId (FORKING_MOJO_ID ThreadLocal + setForkingMojoId) — An improvement over the original PR #12572 on master, which does not have this pattern. It correctly mirrors the existing FORKING_PROJECT_ID save/restore pattern, ensuring the forking mojo's MDC is restored after forked mojos complete.
Previous findings status:
| Finding | Status | Notes |
|---|---|---|
Missing DefaultLogTest.java |
Still open (minor) | Test-parity gap only — functionality works correctly |
mojoSkipped() doesn't clear MDC |
Still open (non-issue) | mojoSkipped is called for mojos that were never started, so MDC is already cleared by the preceding mojo's mojoSucceeded/mojoFailed |
Both remaining items are very minor and don't block the PR.
Additional observation: The ordering change in mojoSucceeded/mojoFailed (delegate runs before MDC clear) is a deliberate improvement — the delegate can still access the mojoId during its callback.
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- 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]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Delta review — checking commit 56f4be34 ("Address review: add DefaultLogTest and clear MDC on mojoSkipped").
Both remaining items from the previous review are now resolved:
| Finding | Status |
|---|---|
Missing DefaultLogTest.java |
✅ Resolved — added with 5 tests: childCreatesSubLogger, warnWithSupplierAndThrowableDelegatesToWarn, traceMethodsDelegateToSlf4jTrace, traceIsNoOpWhenDisabled, defaultTraceIsDisabled |
mojoSkipped() doesn't clear MDC |
✅ Resolved — now calls ProjectBuildLogAppender.setMojoId(null) after delegate, consistent with mojoSucceeded/mojoFailed |
The clearing pattern (clear after delegate call) is consistent across all three mojo lifecycle callbacks. The test suite also covers the warn(Supplier, Throwable) bug fix and trace backward compatibility.
All review findings across 4 rounds are now addressed. 👍
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
* Log API enhancements and mojo MDC (#12690) * 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]> * Address review: javadoc wording in trace methods - "in the trace error level" → "at the trace error level" - "e.g." → "for instance," Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
These methods were backported to maven-4.0.x (#12690) and will be included in 4.0.0-rc-7, so @SInCE should be 4.0.0 not 4.1.0. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.