Skip to content

Migrate internal plumbing DEBUG statements to TRACE level - #12714

Draft
gnodet wants to merge 1 commit into
masterfrom
feature/trace-level-migration
Draft

gnodet wants to merge 1 commit into
masterfrom
feature/trace-level-migration

Conversation

@gnodet

@gnodet gnodet commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Migrates ~70 DEBUG log statements to TRACE in internal plumbing code:
    lifecycle engine, classrealm, cache internals, resolver, plugin resolution
  • Adds TRACE to Slf4jConfiguration.Level enum so the logging system supports
    -Dmaven.logger.defaultLogLevel=trace as a system property for Maven core developers
  • DEBUG (-X) remains the right level for plugin development; TRACE is for
    Maven core developers diagnosing framework internals

Motivation

Separate two audiences:

  • DEBUG — plugin developers and power users diagnosing plugin behavior
  • TRACE — Maven core developers tracing internal framework mechanics

Without this migration, TRACE exists but nothing emits at it, making the distinction
theoretical. This PR populates it with the noisiest internal plumbing output that
dominates -X today and drowns out the signal plugin developers actually want.

What stays at DEBUG

  • Plugin parameter resolution, mojo configuration/loading (useful for plugin devs)
  • mvnup upgrade diagnostics
  • CLI bootstrap messages

Status

This PR is now independent — rebased onto master with no dependency on the
logging PR stack. The original stacked version included unrelated DefaultModelBuilder
changes from the base branch; those have been removed.

Files changed (17 files)

Area Files Changes
Infrastructure Slf4jConfiguration, MavenSimpleConfiguration, CliUtils TRACE level support
Lifecycle engine LifecycleDebugLogger, BuildPlanExecutor, MultiThreadedBuilder ~32 statements
Cache internals DefaultRequestCache, CacheConfigurationResolver ~22 statements
Classrealm DefaultClassRealmManager ~8 statements
Resolver DefaultArtifactDescriptorReader, relocation sources, TypeDeriver ~8 statements
Plugin resolution DefaultPluginVersionResolver, DefaultPluginPrefixResolver ~6 statements
Tests DefaultClassRealmManagerTest, LookupInvokerLoggingTest Updated mocks

Test plan

  • Compilation passes
  • DefaultClassRealmManagerTest passes (mock expectations updated)
  • LookupInvokerLoggingTest passes (new TRACE enum value)
  • CI validation

Related

🤖 Generated with Claude Code

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean mechanical migration of 70+ debug statements to trace level. MavenSimpleConfiguration, CliUtils, and tests are all correctly updated to handle the new Level.TRACE enum value.

Missing TRACE handling in two logging backends:

The new TRACE enum value is correctly handled in MavenSimpleConfiguration (case TRACE -> "trace"), CliUtils (case TRACE, DEBUG ->), and the test, but two other setRootLoggerLevel implementations were not updated:

  • Log4j2Configuration.java (line 32-36): default -> "error" silently maps TRACE to "error" — should add case TRACE -> "trace"
  • LogbackConfiguration.java (line 34-37): default -> ch.qos.logback.classic.Level.ERROR silently maps TRACE to ERROR — should add case TRACE -> ch.qos.logback.classic.Level.TRACE

Both are live code — registered in META-INF/maven/slf4j-configuration.properties as runtime-selected implementations. While Level.TRACE is not yet wired to a CLI option (limiting immediate impact), the inconsistency should be fixed to prevent a silent bug when trace-level CLI support lands.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean mechanical migration of 70+ internal DEBUG statements to TRACE level. All switch expressions, guard conditions, and tests are correctly updated.

Non-blocking observations:

  • LifecycleDebugLogger.debug(String) now calls logger.trace(), making the method name misleading. However, the class is non-public API and renaming would expand the scope unnecessarily.
  • Several trace log calls use string concatenation instead of parameterized logging (pre-existing, not introduced by this PR).
  • Pre-existing arithmetic bug in DefaultModelBuilder.java:2722: afterSize - beforeSize produces a negative count for removed entries. Should be beforeSize - afterSize. This PR only changed the log level.

LGTM — the migration is well-scoped: only internal plumbing is demoted to TRACE, while plugin-facing DEBUG output correctly remains at DEBUG.

This review was generated by an AI agent (Claude Code) and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

gnodet added a commit to gnodet/maven that referenced this pull request Aug 16, 2026
@gnodet gnodet added this to the 4.1.0 milestone Aug 23, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean mechanical migration of 70+ internal DEBUG statements to TRACE level across 18 files. All switch expressions, guard conditions, and tests are correctly updated.

The migration scoping is well-reasoned: only internal framework plumbing (lifecycle engine, classrealm, cache internals, resolver, model builder, plugin resolution) is demoted to TRACE. Plugin-facing DEBUG output (parameter resolution, mojo configuration) correctly remains at DEBUG, preserving the signal that plugin developers need from -X.

Note: the two prior AI-generated reviews flagged Log4j2Configuration and LogbackConfiguration as missing TRACE handling — this is a false positive since both files were removed in an earlier PR in the chain and do not exist on the target branch feature/12643-structured-problems.

Looks good overall. ✅


This review was generated by an AI agent (Claude Code) and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@gnodet
gnodet force-pushed the feature/trace-level-migration branch from 2a79603 to 6eff81f Compare August 28, 2026 09:28
@gnodet
gnodet force-pushed the feature/12643-structured-problems branch from b6a409b to 4b6969b Compare August 28, 2026 09:28

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean mechanical migration of 70+ internal DEBUG statements to TRACE across 18 files. The scoping is well-reasoned — only internal framework plumbing (lifecycle engine, classrealm, cache internals, resolver, model builder, plugin resolution) is demoted to TRACE, while plugin-facing DEBUG output (parameter resolution, mojo configuration) correctly remains at DEBUG.

The Slf4jConfiguration.Level enum update is correctly propagated to MavenSimpleConfiguration, and the CliUtils mapping functions correctly map TRACE to the same level as DEBUG for legacy APIs that lack a TRACE concept.

A few minor pre-existing observations (not introduced by this PR):

  • DefaultModelBuilder.java line ~2722: afterSize - beforeSize produces a negative value when reporting "removed {} entries" — should be beforeSize - afterSize
  • LifecycleDebugLogger: Several trace log calls use string concatenation instead of parameterized logging ("Project: " + ... vs "Project: {}", ...)
  • The compat/maven-resolver-provider TypeDeriver still has debug() calls for the same messages migrated to trace() in the impl/ version — acceptable since compat modules are legacy wrappers

LGTM — the rebase introduced no content changes and the migration is correct throughout.

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

@gnodet
gnodet force-pushed the feature/12643-structured-problems branch from 4b6969b to 3b439d0 Compare August 28, 2026 09:55
@gnodet
gnodet force-pushed the feature/trace-level-migration branch from 6eff81f to 6c40a9e Compare August 28, 2026 09:55
@gnodet
gnodet force-pushed the feature/12643-structured-problems branch from 3b439d0 to 5f53884 Compare August 28, 2026 10:16
@gnodet
gnodet force-pushed the feature/trace-level-migration branch from 6c40a9e to 7a6b6ad Compare August 28, 2026 10:16
@gnodet
gnodet force-pushed the feature/12643-structured-problems branch from 5f53884 to a964976 Compare August 31, 2026 08:55
@gnodet
gnodet force-pushed the feature/trace-level-migration branch from 7a6b6ad to 2d77564 Compare August 31, 2026 08:55
@gnodet
gnodet force-pushed the feature/12643-structured-problems branch from a964976 to 33f16e8 Compare September 18, 2026 11:11
@gnodet
gnodet force-pushed the feature/trace-level-migration branch from 2d77564 to 0d2db3b Compare September 18, 2026 11:11
@gnodet
gnodet force-pushed the feature/12643-structured-problems branch from 33f16e8 to 0661b09 Compare September 18, 2026 11:21
@gnodet
gnodet force-pushed the feature/trace-level-migration branch from 0d2db3b to b282ea5 Compare September 18, 2026 11:21

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logging migration itself (DEBUG → TRACE for 70+ statements) is clean and well-scoped. The Slf4jConfiguration.Level.TRACE enum addition, switch propagation in CliUtils/MavenSimpleConfiguration, and test updates are all correct.

However, the DefaultModelBuilder.java diff includes several non-logging functional changes that revert or weaken fixes that were already present on the base branch (feature/12643-structured-problems). These need to be addressed before merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

// to prevent StackOverflowError from path representation mismatches (GH-12598).
Path normalizedPath =
sourcePath != null ? sourcePath.toAbsolutePath().normalize() : null;
Path normalizedPath = sourcePath != null ? sourcePath.normalize() : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Regression (GH-12598): sourcePath.normalize() without toAbsolutePath()

The base branch used sourcePath.toAbsolutePath().normalize() here to ensure a canonical, absolute path is stored in activeModelReads. The comment that was removed explicitly explained why:

Use toAbsolutePath().normalize() for consistent path identity in activeModelReads. This must match the normalization used in getEnhancedProperties() guard check to prevent StackOverflowError from path representation mismatches (GH-12598).

With only .normalize(), a relative sourcePath (e.g. when modelSource.getPath() returns a relative Path) will be stored as-is. The guard in getEnhancedProperties at line 751 uses rootModelPath.normalize() — also without toAbsolutePath(). If the two paths represent the same file but one is absolute and one is relative, the contains() check returns false and the StackOverflow reappears on projects that triggered GH-12598.

Suggested change
Path normalizedPath = sourcePath != null ? sourcePath.normalize() : null;
Path normalizedPath = sourcePath != null ? sourcePath.toAbsolutePath().normalize() : null;

if (isParentWithinRootDirectory(rootModelPath, rootDirectory)
&& !activeModelReads.contains(
rootModelPath.toAbsolutePath().normalize())) {
&& !activeModelReads.contains(rootModelPath.normalize())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Regression (GH-12301/GH-12598): rootModelPath.normalize() without toAbsolutePath()

The base branch guard was rootModelPath.toAbsolutePath().normalize() to match the identity of entries put into activeModelReads by doReadFileModel. That comment was deleted here:

Use toAbsolutePath().normalize() for the guard check to handle paths obtained via different representations (e.g., symlinks, relative segments).

The rootModelPath comes from modelProcessor.locateExistingPom(rootDirectory). If that returns a relative or symlinked path while the entry in activeModelReads is an absolute path (or vice versa), the cycle guard fires when it shouldn't, or misses when it should fire.

Suggested change
&& !activeModelReads.contains(rootModelPath.normalize())) {
&& !activeModelReads.contains(rootModelPath.toAbsolutePath().normalize())) {

return dominant;
return List.copyOf(
request.getRepositories() != null
? request.getRepositories()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Regression (MNG-12769): mergeRepositoriesById removed

The base branch's repos() method called mergeRepositoriesById() which merged duplicate repo entries (same ID, different snapshot/release policies) that mirror injection can produce. The Javadoc explained:

Without this merge, policy deduplication in the resolver can drop the snapshot policy, causing SNAPSHOT parent resolution to fail (MNG-12769).

This PR replaces repos() with a plain List.copyOf(...), silently reintroducing the MNG-12769 bug for projects that use mirrors with split release/snapshot policies.

The fix should be re-applied here, or moved to a layer below ModelBuilderSessionState if the intent is to clean up its scope.

Migrates ~70 DEBUG log statements to TRACE in internal plumbing code:
lifecycle engine, classrealm, cache internals, resolver, plugin resolution.

DEBUG (-X) remains the right level for plugin development.
TRACE is for Maven core developers diagnosing framework internals,
accessible via -Dmaven.logger.defaultLogLevel=trace.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@gnodet
gnodet force-pushed the feature/trace-level-migration branch from b282ea5 to fdab681 Compare October 16, 2026 09:31
@gnodet
gnodet changed the base branch from feature/12643-structured-problems to master October 16, 2026 09:31

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier review — the DefaultModelBuilder.java issues (sourcePath normalization, rootModelPath normalization, mergeRepositoriesById) are all resolved: the PR has been rebased onto master and those changes have been removed from the diff entirely. ✅

The logging migration itself is clean and correctly applied across all 17 files. One issue remains before merge:

Missing case TRACE in LogbackConfiguration and Log4j2Configuration

MavenSimpleConfiguration was correctly updated with case TRACE -> "trace". But two sibling implementations were not:

  • LogbackConfiguration.java (line 34–37): uses default -> ch.qos.logback.classic.Level.ERROR, so Level.TRACE maps silently to ERROR
  • Log4j2Configuration.java (line 32–35): uses default -> "error", same silent failure

Currently no code path sets context.loggerLevel = Level.TRACE in LookupInvoker, so this is latent. But the PR description explicitly advertises -Dmaven.logger.defaultLogLevel=trace support — when that path is wired, users on Logback/Log4j2 backends will get ERROR output instead of TRACE with zero diagnostic indication. Add explicit case TRACE arms to both.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

* Level
*/
enum Level {
TRACE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding TRACE here requires updating all Slf4jConfiguration implementations. MavenSimpleConfiguration is updated ✅ but LogbackConfiguration and Log4j2Configuration both use default -> ERROR — Level.TRACE will silently map to ERROR on those backends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants