This is an automated email from the ASF dual-hosted git repository.
ppkarwasz pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new d0c00e953a Add missing setters to `Rfc5424LayoutBuilder` (#4076)
d0c00e953a is described below
commit d0c00e953abf9fd4b21c1269a74f4efdee8740df
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Sun Apr 19 15:11:09 2026 +0200
Add missing setters to `Rfc5424LayoutBuilder` (#4076)
* Restore support for documented `Rfc5424Layout` attributes
In `2.21.0`, `Rfc5424Layout` was migrated from a factory method to the
builder pattern. During this change, the recognized names of several
configuration attributes unintentionally diverged from the documented ones.
As a result, some documented attributes were no longer recognized, while
new, undocumented names were introduced.
This change restores support for the documented attribute names while
continuing to accept the names introduced in `2.21.0` for backward
compatibility.
Fixes #4022
Co-authored-by: Volkan Yazıcı <[email protected]>
* Add missing setters to `Rfc5424LayoutBuilder`
This change introduces setter methods for the private fields added to
`Rfc5424LayoutBuilder` in version `2.25.4`.
These fields were originally introduced to restore configuration options
that existed in `2.20.0` but were unintentionally renamed in `2.21.0`. Due to
semantic versioning constraints, setters were not added at that time.
With the `2.26.0` release, it is now appropriate to expose these fields via
setters, restoring full configurability and improving API usability.
* fix: wrong reference in Javadoc
---------
Co-authored-by: Volkan Yazıcı <[email protected]>
---
.../log4j/core/layout/Rfc5424LayoutTest.java | 6 +-
.../log4j/core/appender/SyslogAppender.java | 12 +--
.../logging/log4j/core/layout/Rfc5424Layout.java | 90 +++++++++++++++++++---
src/changelog/.2.x.x/rfc5424-setters.xml | 11 +++
4 files changed, 98 insertions(+), 21 deletions(-)
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
index d4371b90dc..0eaac7c9f8 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
@@ -747,10 +747,10 @@ class Rfc5424LayoutTest {
.setEin("1234.56.7")
.setIncludeMDC(true)
.setMdcId("RequestContext")
- .setIncludeNL(true)
+ .setNewLine(true)
.setAppName("ATM")
- .setExcludes("key1, key2, locale")
- .setUseTLSMessageFormat(true)
+ .setMdcExcludes("key1, key2, locale")
+ .setUseTlsMessageFormat(true)
.build();
final ListAppender appender = new ListAppender("List", null, layout,
true, false);
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
index 21af109bd2..a1726b2952 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
@@ -121,15 +121,15 @@ public class SyslogAppender extends SocketAppender {
.setMdcId(mdcId)
.setMdcPrefix(mdcPrefix)
.setEventPrefix(eventPrefix)
- .setIncludeNL(newLine)
- .setEscapeNL(escapeNL)
+ .setNewLine(newLine)
+ .setNewLineEscape(escapeNL)
.setAppName(appName)
.setMessageId(msgId)
- .setExcludes(excludes)
- .setIncludes(includes)
- .setRequired(required)
+ .setMdcExcludes(excludes)
+ .setMdcIncludes(includes)
+ .setMdcRequired(required)
.setExceptionPattern(exceptionPattern)
- .setUseTLSMessageFormat(useTlsMessageFormat)
+ .setUseTlsMessageFormat(useTlsMessageFormat)
.setLoggerFields(loggerFields)
.setConfiguration(configuration)
.build()
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
index 6a1ba5da0c..461c707a0a 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
@@ -751,19 +751,19 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
.setId(id)
.setEin(String.valueOf(enterpriseNumber))
.setIncludeMDC(includeMDC)
- .setIncludeNL(newLine)
- .setEscapeNL(escapeNL)
+ .setNewLine(newLine)
+ .setNewLineEscape(escapeNL)
.setMdcId(mdcId)
.setMdcPrefix(mdcPrefix)
.setEventPrefix(eventPrefix)
.setAppName(appName)
.setMessageId(msgId)
- .setExcludes(excludes)
- .setIncludes(includes)
- .setRequired(required)
+ .setMdcExcludes(excludes)
+ .setMdcIncludes(includes)
+ .setMdcRequired(required)
.setCharset(StandardCharsets.UTF_8)
.setExceptionPattern(exceptionPattern)
- .setUseTLSMessageFormat(useTlsMessageFormat)
+ .setUseTlsMessageFormat(useTlsMessageFormat)
.setLoggerFields(loggerFields)
.build();
}
@@ -829,7 +829,6 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
*
* <p>Default is {@code false}.</p>
*/
- @SuppressWarnings("log4j.public.setter")
@PluginBuilderAttribute
private boolean newLine;
@@ -846,7 +845,6 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
*
* <p>By default, new lines are not escaped.</p>
*/
- @SuppressWarnings("log4j.public.setter")
@PluginBuilderAttribute
private String newLineEscape;
@@ -898,7 +896,6 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
*
* <p>Mutually exclusive with {@link #mdcIncludes}.</p>
*/
- @SuppressWarnings("log4j.public.setter")
@PluginBuilderAttribute
private String mdcExcludes;
@@ -915,7 +912,6 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
*
* <p>Mutually exclusive with {@link #mdcExcludes}.</p>
*/
- @SuppressWarnings("log4j.public.setter")
@PluginBuilderAttribute
private String mdcIncludes;
@@ -930,7 +926,6 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
/**
* A comma separated list of MDC keys that must be present in the MDC.
*/
- @SuppressWarnings("log4j.public.setter")
@PluginBuilderAttribute
private String mdcRequired;
@@ -953,7 +948,6 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
*
* <p>Default is {@code false}.</p>
*/
- @SuppressWarnings("log4j.public.setter")
@PluginBuilderAttribute
private boolean useTlsMessageFormat;
@@ -1002,16 +996,40 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
return this;
}
+ /**
+ * @deprecated Since 2.26.0 use {@link #setNewLine} instead.
+ */
+ @Deprecated
public Rfc5424LayoutBuilder setIncludeNL(final boolean includeNL) {
this.includeNL = includeNL;
return this;
}
+ /**
+ * @since 2.26.0
+ */
+ public Rfc5424LayoutBuilder setNewLine(boolean newLine) {
+ this.newLine = newLine;
+ return this;
+ }
+
+ /**
+ * @deprecated Since 2.26.0 use {@link #setNewLineEscape} instead.
+ */
+ @Deprecated
public Rfc5424LayoutBuilder setEscapeNL(final String escapeNL) {
this.escapeNL = escapeNL;
return this;
}
+ /**
+ * @since 2.26.0
+ */
+ public Rfc5424LayoutBuilder setNewLineEscape(String newLineEscape) {
+ this.newLineEscape = newLineEscape;
+ return this;
+ }
+
public Rfc5424LayoutBuilder setMdcId(final String mdcId) {
this.mdcId = mdcId;
return this;
@@ -1037,21 +1055,57 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
return this;
}
+ /**
+ * @deprecated since 2.26.0 use {@link #setMdcExcludes} instead
+ */
+ @Deprecated
public Rfc5424LayoutBuilder setExcludes(final String excludes) {
this.excludes = excludes;
return this;
}
+ /**
+ * @since 2.26.0
+ */
+ public Rfc5424LayoutBuilder setMdcExcludes(String mdcExcludes) {
+ this.mdcExcludes = mdcExcludes;
+ return this;
+ }
+
+ /**
+ * @deprecated since 2.26.0 use {@link #setMdcIncludes} instead
+ */
+ @Deprecated
public Rfc5424LayoutBuilder setIncludes(String includes) {
this.includes = includes;
return this;
}
+ /**
+ * @since 2.26.0
+ */
+ public Rfc5424LayoutBuilder setMdcIncludes(String mdcIncludes) {
+ this.mdcIncludes = mdcIncludes;
+ return this;
+ }
+
+ /**
+ * @deprecated since 2.26.0 use {@link #setMdcRequired} instead
+ */
+ @Deprecated
public Rfc5424LayoutBuilder setRequired(final String required) {
this.required = required;
return this;
}
+ /**
+ * @since 2.26.0
+ */
+ public Rfc5424LayoutBuilder setMdcRequired(String mdcRequired) {
+ this.mdcRequired = mdcRequired;
+ return this;
+ }
+
// Kept for binary compatibility
public Rfc5424LayoutBuilder setCharset(final Charset charset) {
return super.setCharset(charset);
@@ -1062,11 +1116,23 @@ public final class Rfc5424Layout extends
AbstractStringLayout {
return this;
}
+ /**
+ * @deprecated since 2.26.0 use {@link #setUseTlsMessageFormat} instead
+ */
+ @Deprecated
public Rfc5424LayoutBuilder setUseTLSMessageFormat(final boolean
useTLSMessageFormat) {
this.useTLSMessageFormat = useTLSMessageFormat;
return this;
}
+ /**
+ * @since 2.26.0
+ */
+ public Rfc5424LayoutBuilder setUseTlsMessageFormat(boolean
useTlsMessageFormat) {
+ this.useTlsMessageFormat = useTlsMessageFormat;
+ return this;
+ }
+
public Rfc5424LayoutBuilder setLoggerFields(final LoggerFields[]
loggerFields) {
this.loggerFields = loggerFields;
return this;
diff --git a/src/changelog/.2.x.x/rfc5424-setters.xml
b/src/changelog/.2.x.x/rfc5424-setters.xml
new file mode 100644
index 0000000000..4cd3cde732
--- /dev/null
+++ b/src/changelog/.2.x.x/rfc5424-setters.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ https://logging.apache.org/xml/ns
+ https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="added">
+ <description format="asciidoc">
+ Add missing setters to `Rfc5424LayoutBuilder`.
+ </description>
+</entry>