Skip to content

[#14188] Add lazy arguments to the fluent log event builder - #14215

Open
VirtualSelect wants to merge 1 commit into
apache:masterfrom
VirtualSelect:maven-14188-fluent-log-arguments
Open

VirtualSelect wants to merge 1 commit into
apache:masterfrom
VirtualSelect:maven-14188-fluent-log-arguments

Conversation

@VirtualSelect

@VirtualSelect VirtualSelect commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

  • Add addArgument(Object) and addArgument(Supplier<?>) to LogEventBuilder. Enabled builders evaluate each supplier at the call site; disabled builders never invoke it.
  • Preserve insertion order, including when the terminal template call supplies additional arguments. The standard logger still forwards the raw template and arguments; bootstrap keeps its existing formatting.
  • Leave terminal supplier overloads and call-site migration out of this first slice, as agreed on the issue.

Verification

  • JDK 17: Spotless and the 14-module focused reactor passed, including all 20 tests in DefaultLoggerTest, BufferingArgumentTest, and LoggerManagerHolderTest.
  • Bootstrap mutation control: dropping the builder's added arguments from terminal dispatch caused the regression test to fail; the submitted code passes.
  • Full -Prun-its verify stopped in maven-impl with five resolver-related test errors. The same five tests fail with the same exception types on the unmodified base. Both logs show the standalone resolver cannot resolve Maven Central in this environment (UnknownHostException). Full integration verification is not claimed.

Addresses #14188 (fluent API slice only).

AI assistance: OpenAI Codex.

Keep argument suppliers behind the level check and preserve the original
message template and argument order, including during bootstrap.

Generated-by: OpenAI Codex
@github-actions

This comment has been minimized.

@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 addArgument(Object) and addArgument(Supplier<?>) additions look solid — the implementation is clean, the NopLogEventBuilder/BufferingLoggerManager.NOP both short-circuit correctly, and the test coverage for argument ordering, prepend semantics, and disabled-level evaluation is thorough.

One thing that needs to be addressed: the log(String, Supplier<?>) and log(String, Supplier<?>, Supplier<?>) convenience overloads are missing from the LogEventBuilder interface.

We discussed these in #14188. The PR description says they were left aside "as agreed", but looking back at the issue thread, the only agreement was to leave the call-site migration (replacing isDebugEnabled() guards) out of this first slice — not the convenience overloads. Those were explicitly endorsed:

"One note on the log(format, null) ambiguity you spotted: the log(String, Supplier<?>) / log(String, Supplier<?>, Supplier<?>) overloads are convenience defaults on the interface. Since null is not a valid Supplier<?> argument in practice, I'm not too worried about the ambiguity in real code…"

These are default methods on the interface, so they're a trivial addition:

default void log(@Nonnull String format, @Nonnull Supplier<?> arg) {
    addArgument(arg).log(format);
}

default void log(@Nonnull String format, @Nonnull Supplier<?> arg1, @Nonnull Supplier<?> arg2) {
    addArgument(arg1).addArgument(arg2).log(format);
}

They enable the idiomatic single-expression form that was the main motivation for the issue:

logger.atDebug().log("Reading file model from {0}", modelSource::getLocation);

Without them, callers have to chain addArgument(...).log(format) manually every time — which works but is more verbose than it needs to be. Please add them before this is merged.

@VirtualSelect

Copy link
Copy Markdown
Author

Thanks for the review. @gnodet, should the two log(..., Supplier<?>) convenience overloads be part of this PR, or should this one stay focused on addArgument?

I checked the overloads with javac: log(format, null) currently compiles (with a varargs warning), but adding log(String, Supplier<?>) makes it ambiguous with log(String, Object...). Adding the two-supplier overload also changes which method an existing log(format, null, null) call selects. I'd keep the current slice as-is unless you want to accept those source-compatibility changes here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants