Interface LogEventBuilder
Instances are obtained from Logger.atTrace(), Logger.atDebug(), etc.
A builder must be consumed in a single chained call; it must not be
stored in a variable across statements, as implementations may reuse
thread-local state for zero-allocation dispatch.
When the target level is disabled the Logger returns a shared
NopLogEventBuilder singleton, making the entire fluent call chain a no-op
with zero allocations.
log.atInfo()
.withKeyValue("module", module.getId())
.log("Compiling {} source files", count);
Message format
The log(String format, Object...) family of methods uses a simple
positional placeholder syntax: each occurrence of {} in the format
string is replaced, in order, by the string representation of the corresponding
argument. No index, type specifier, or locale conversion is supported — this is
intentionally simpler than MessageFormat and avoids the
injection risk of printf-style specifiers.
Example: log("Building {} module(s) in {}", count, dir) produces
"Building 3 module(s) in /tmp/build" when count=3 and
dir="/tmp/build".
This convention is the same as the one used by SLF4J
(MessageFormatter),
which is widely used in the Java ecosystem and is already the format employed
by plugin.Log, the API this interface replaces.
- Since:
- 4.0.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidEmits the log event with the given pre-formatted message.voidEmits the log event with a SLF4J-style{}template and a single argument.voidEmits the log event with a SLF4J-style{}template and any number of arguments.voidEmits the log event with a SLF4J-style{}template and two arguments.voidEmits the log event with a lazily-evaluated message supplier.withKeyValue(String key, boolean value) Attaches a structured key-value pair with abooleanvalue.withKeyValue(String key, long value) Attaches a structured key-value pair with alongvalue.withKeyValue(String key, String value) Attaches a structured key-value pair to this log event.withMojoId(String mojoId) Overrides the mojo execution identifier for this event.withProjectId(String projectId) Overrides the project identifier for this event.Attaches aThrowableto this log event.
-
Method Details
-
withKeyValue
Attaches a structured key-value pair to this log event.Structured key-value pairs are consumed by structured log appenders (e.g. JSON, ECS, or Logstash layouts in Logback or Log4j 2) that capture fields alongside the message text — rather than embedding metadata inside the message string itself. This enables log aggregators such as Elasticsearch or Splunk to filter and correlate events by field values directly.
In a Maven context, typical uses include attaching build metadata such as project coordinates, mojo identifiers, and elapsed time as first-class indexed fields. When running with a plain-text appender these pairs are silently ignored or appended after the message, depending on the appender configuration.
- Parameters:
key- the field name, nevernullvalue- the string value- Returns:
- this builder
-
withKeyValue
Attaches a structured key-value pair with alongvalue.See
withKeyValue(String, String)for the purpose of structured key-value pairs.- Parameters:
key- the field name, nevernullvalue- the numeric value- Returns:
- this builder
-
withKeyValue
Attaches a structured key-value pair with abooleanvalue.See
withKeyValue(String, String)for the purpose of structured key-value pairs.- Parameters:
key- the field name, nevernullvalue- the boolean value- Returns:
- this builder
-
withThrowable
Attaches aThrowableto this log event.- Parameters:
t- the throwable, may benull(no-op)- Returns:
- this builder
-
withProjectId
Overrides the project identifier for this event.Note: enrichment via this method is best-effort and implementation-defined. Implementations that do not support per-event project context may silently ignore the supplied value.
- Parameters:
projectId- the project id, ornullto clear- Returns:
- this builder
-
withMojoId
Overrides the mojo execution identifier for this event.Note: enrichment via this method is best-effort and implementation-defined. Implementations that do not support per-event mojo context may silently ignore the supplied value.
- Parameters:
mojoId- the mojo id, ornullto clear- Returns:
- this builder
-
log
Emits the log event with the given pre-formatted message.- Parameters:
message- the message, nevernull
-
log
Emits the log event with a SLF4J-style{}template and a single argument.Fast path that avoids varargs array allocation.
- Parameters:
format- the message templatearg- the single argument
-
log
Emits the log event with a SLF4J-style{}template and two arguments.Fast path that avoids varargs array allocation.
- Parameters:
format- the message templatearg1- the first argumentarg2- the second argument
-
log
Emits the log event with a SLF4J-style{}template and any number of arguments.- Parameters:
format- the message templateargs- the arguments
-
log
Emits the log event with a lazily-evaluated message supplier.The supplier is only invoked when the level is enabled. When this builder is a NOP instance the supplier is never called.
- Parameters:
messageSupplier- a supplier of the log message, nevernull
-