maven icon indicating copy to clipboard operation
maven copied to clipboard

Define SLF4J 2.0 key-value conventions for plugin diagnostic metadata

Open gnodet opened this issue 1 month ago • 2 comments

Context

Maven uses SLF4J 2.0.20 which supports the fluent API with key-value pairs:

logger.atWarn()
      .addKeyValue("maven.diagnostic.key", "deprecated-source-target")
      .addKeyValue("maven.diagnostic.suggestion", "Use release flag instead")
      .setMessage("source/target 8 is deprecated")
      .log();

The logging stack (PR #12694) auto-captures WARN-level log events and creates synthetic BuilderProblem objects with hash-based keys (auto:logger-name:hash). These lack the structured metadata that DiagnosticReporter provides (key, suggestion, documentationUrl).

Proposal

Define a set of well-known SLF4J key-value key conventions:

Key Type Description
maven.diagnostic.key String Stable dedup key (e.g., deprecated-source-target)
maven.diagnostic.suggestion String Actionable fix text
maven.diagnostic.documentationUrl String Link to relevant docs
maven.diagnostic.source String Source file path
maven.diagnostic.line int Line number

When MavenSimpleLogger captures a WARN event, it checks for these KV pairs on the LoggingEvent and uses them to create richer BuilderProblem objects instead of falling back to hash-based synthetic keys.

Benefits

  • Plugins can emit structured warnings using standard SLF4J without depending on maven-api-core or DiagnosticReporter
  • Migration stepping stone: Log.warn() → SLF4J KV pairs → full DiagnosticReporter
  • JUL has no equivalent (no extensible KV support on LogRecord), but this is fine — JUL callers are external libraries, not Maven plugins

Related

  • #12694 — Logging foundation PR
  • #12571 — Build output overhaul tracking issue

🤖 Drafted with Claude Code (Claude Opus 4.6). Reviewed and confirmed by @gnodet before submission.

gnodet avatar Oct 16 '26 09:10 gnodet

Hi @gnodet,

I looked into the proposed SLF4J key-value conventions and their integration with Maven's diagnostic pipeline. Since this appears closely related to the ongoing build output overhaul, I wanted to clarify the intended scope before starting any implementation.

Do you intend to include this functionality as part of PR #12698 (feature/warning-mode), or would you prefer it as a separate follow-up PR after #12698 and the related build output changes are merged?

I'd be happy to investigate or contribute once the implementation direction is clear, and I want to avoid duplicating or conflicting with the ongoing work.

Thanks!

harshab054 avatar Oct 20 '26 02:10 harshab054

Hi,

I looked into the warning-mode implementation in PR #12698 and the proposed SLF4J key-value conventions.

I would like to contribute to this issue by adding support for structured diagnostic metadata when WARN-level logging events are converted into BuilderProblem objects.

Should this be implemented as a separate follow-up PR, or is this functionality already planned as part of the ongoing diagnostic pipeline work?

Thanks!

codewithsinchana avatar Oct 27 '26 03:10 codewithsinchana