Logging foundation: structured LogEvent, JUL handler, Log API enhancements - #12694
Draft
gnodet wants to merge 1 commit into
Draft
Logging foundation: structured LogEvent, JUL handler, Log API enhancements#12694gnodet wants to merge 1 commit into
gnodet wants to merge 1 commit into
Conversation
Lay the groundwork for structured build reporting and richer log capture by introducing: - Log.trace() level (5 overloads + isTraceEnabled) to separate Maven core internals from user-facing debug output - Log.child(name) for hierarchical sub-loggers - LogEvent/LogLevel API for structured log event representation, including optional JUL metadata (sourceClassName, sourceMethodName, threadId) that the standard SLF4J bridge silently drops - MavenJulHandler: a custom java.util.logging Handler that replaces SLF4JBridgeHandler, preserving full LogRecord metadata through a ThreadLocal read by ProjectBuildLogAppender - Structured LogSink in MavenSimpleLogger (level, logger name, clean message, formatted output, throwable) replacing the old string sink - mojoId MDC (maven.mojo.id) set during mojo execution so all log messages carry mojo context - Logger name changed from getFullGoalName() to getImplementation() (FQCN) for proper hierarchical SLF4J level control - Fix: DefaultLog.warn(Supplier, Throwable) was calling logger.info() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
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
Focused, reviewable PR that lays the logging infrastructure foundation for the build report work (#12572). Split out from #12572 to enable focused review and discussion of the logging architecture.
What's included
Log API enhancements (
maven-api-core)Log.trace()— 5 overloads +isTraceEnabled()to separate Maven core internals (trace) from user-facing debug output (debug). Maps to SLF4J TRACE / JUL FINEST.Log.child(name)— hierarchical sub-loggers for plugins that want to separate concerns while keeping level control. Default implementation returnsthisfor backward compatibility.Structured LogEvent (
maven-api-core,maven-core)LogEvent/LogLevelAPI for structured log event representationsourceClassName(),sourceMethodName(),threadId()— populated only for events originating fromjava.util.logging,nullfor SLF4J/Log API eventsCustom JUL Handler (
maven-logging)MavenJulHandlerreplacesSLF4JBridgeHandler— reimplements JUL→SLF4J bridging while preserving the fullLogRecordmetadata that the standard bridge silently dropsProjectBuildLogAppenderduring the samepublish()callMavenJulHandler→ SLF4J — all converge on the same structuredLogEventStructured LogSink (
maven-logging,maven-core)MavenSimpleLogger.LogSink— structured callback with(level, loggerName, cleanMessage, formattedMessage, throwable)replacing the oldConsumer<String>sinkProjectBuildLogAppenderproducesLogEventobjects (with JUL metadata when available) instead of raw stringsBuildEventListener.projectLogMessage()now takesLogEventinstead ofStringMojo MDC & logger name (
maven-core)maven.mojo.idMDC key set during mojo execution (format:prefix:goal@executionId)getFullGoalName()("compiler:compile") togetImplementation()(FQCN likeorg.apache.maven.plugins.compiler.CompilerMojo) for proper hierarchical SLF4J level configurationBug fix
DefaultLog.warn(Supplier<String>, Throwable)was callinglogger.info()instead oflogger.warn()Context
This is Part 1 of the #12572 split. The build report, console modes, and warning mode features will follow as separate PRs on top of this foundation. See discussion in the dev@ thread and Martin's feedback on JUL field preservation.
Depends on / blocks
Test plan
mvn test -pl impl/maven-core,impl/maven-logging— 580 tests pass🤖 Generated with Claude Code