You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/08/07 09:32:24 UTC
[PR] Backport Log API enhancements and mojo MDC to 4.0.x [maven]
gnodet opened a new pull request, #12690:
URL: https://github.com/apache/maven/pull/12690
## Summary
Backport four Log-related improvements from master ([#12572](https://github.com/apache/maven/pull/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
- [x] `mvn test -pl impl/maven-core` passes locally
- [ ] CI on maven-4.0.x branch
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log API enhancements and mojo MDC [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #12690:
URL: https://github.com/apache/maven/pull/12690
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Backport Log API enhancements and mojo MDC to 4.0.x [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #12690:
URL: https://github.com/apache/maven/pull/12690#issuecomment-5464490499
Applied review fixes from #12694 to align the backport:
**1. `Log.java` — default trace methods (prevents `AbstractMethodError`)**
All 6 trace methods (`isTraceEnabled` + 5 overloads) now have `default` implementations — `isTraceEnabled()` returns `false` by default, all `trace(...)` overloads are no-ops. This prevents `AbstractMethodError` for existing third-party `Log` implementors (even though `@Experimental`+`@Provider`, this is the safe thing to do).
**2. `ProjectBuildLogAppender` — fork-aware mojoId**
Added `FORKING_MOJO_ID` ThreadLocal mirroring the existing `FORKING_PROJECT_ID` pattern. When `setMojoId(null)` is called after a fork completes, the forking mojo's ID is restored instead of simply clearing. This fixes the case where a forking mojo (e.g. a report goal) resumes after its fork — log messages during the resumed execution now correctly carry the mojo ID.
**3. `LoggingExecutionListener` — fork save/restore + cleanup ordering**
- `forkStarted()` now saves the current mojoId via `setForkingMojoId()`
- `forkSucceeded()`/`forkFailed()` clear the forking mojoId
- `mojoSucceeded()`/`mojoFailed()` now run the delegate *before* clearing the MDC (matching #12694's ordering)
Build: compiles cleanly and passes all maven-core tests (562 tests, 2 pre-existing failures unrelated to logging).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org