diff --git a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java
index f5db0cfc..9e48ee68 100644
--- a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java
+++ b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java
@@ -101,7 +101,9 @@ private ExtendedPatternLayout(
boolean disableAnsi,
boolean noConsoleNoAnsi,
String headerPattern,
- String footerPattern) {
+ String footerPattern,
+ boolean initNewLine,
+ boolean prettyPrinting) {
super(
config,
charset,
@@ -113,6 +115,8 @@ private ExtendedPatternLayout(
.setDisableAnsi(disableAnsi)
.setNoConsoleNoAnsi(noConsoleNoAnsi)
.setPattern(headerPattern)
+ .setInitNewLine(initNewLine)
+ .setPrettyPrinting(prettyPrinting)
.build(),
newSerializerBuilder()
.setConfiguration(config)
@@ -122,6 +126,8 @@ private ExtendedPatternLayout(
.setDisableAnsi(disableAnsi)
.setNoConsoleNoAnsi(noConsoleNoAnsi)
.setPattern(footerPattern)
+ .setInitNewLine(initNewLine)
+ .setPrettyPrinting(prettyPrinting)
.build());
conversionPattern = eventPattern;
this.patternSelector = patternSelector;
@@ -135,6 +141,8 @@ private ExtendedPatternLayout(
.setNoConsoleNoAnsi(noConsoleNoAnsi)
.setPattern(eventPattern)
.setDefaultPattern("%m%n")
+ .setInitNewLine(initNewLine)
+ .setPrettyPrinting(prettyPrinting)
.build();
}
@@ -339,6 +347,8 @@ public static ExtendedPatternLayout createLayout(
.withNoConsoleNoAnsi(noConsoleNoAnsi)
.withHeader(headerPattern)
.withFooter(footerPattern)
+ .withInitNewLine(false)
+ .withPrettyPrinting(false)
.build();
}
@@ -404,12 +414,8 @@ public static final class Builder
@PluginBuilderAttribute private boolean noConsoleNoAnsi;
@PluginBuilderAttribute private String header;
@PluginBuilderAttribute private String footer;
-
- @PluginBuilderAttribute("initNewLine")
- private static boolean initNewLine;
-
- @PluginBuilderAttribute("prettyPrinting")
- private static boolean prettyPrinting;
+ @PluginBuilderAttribute private boolean initNewLine;
+ @PluginBuilderAttribute private boolean prettyPrinting;
private Builder() {
super();
@@ -541,6 +547,28 @@ public ExtendedPatternLayout.Builder withFooter(String footer) {
return this;
}
+ /**
+ * Sets whether to start byte array output on a new line.
+ *
+ * @param initNewLine Whether to initialize byte array output on a new line
+ * @return This builder instance
+ */
+ public ExtendedPatternLayout.Builder withInitNewLine(boolean initNewLine) {
+ this.initNewLine = initNewLine;
+ return this;
+ }
+
+ /**
+ * Sets whether to format byte arrays with spaces between bytes for readability.
+ *
+ * @param prettyPrinting Whether to pretty print byte arrays
+ * @return This builder instance
+ */
+ public ExtendedPatternLayout.Builder withPrettyPrinting(boolean prettyPrinting) {
+ this.prettyPrinting = prettyPrinting;
+ return this;
+ }
+
/**
* Builds a new ExtendedPatternLayout instance with the configured settings.
*
@@ -565,7 +593,9 @@ public ExtendedPatternLayout build() {
disableAnsi,
noConsoleNoAnsi,
header,
- footer);
+ footer,
+ initNewLine,
+ prettyPrinting);
}
}
@@ -655,6 +685,8 @@ public SerializerBuilder() {
private boolean alwaysWriteExceptions;
private boolean disableAnsi;
private boolean noConsoleNoAnsi;
+ private boolean initNewLine;
+ private boolean prettyPrinting;
/**
* Builds a serializer for formatting log events according to the configured settings.
@@ -685,7 +717,7 @@ public AbstractStringLayout.Serializer build() {
noConsoleNoAnsi);
PatternFormatter[] formatters = list.toArray(new PatternFormatter[0]);
return new ExtendedPatternLayout.ExtendedPatternLayoutSerializer(
- formatters, replace);
+ formatters, replace, initNewLine, prettyPrinting);
} catch (RuntimeException var4) {
throw new IllegalArgumentException(
"Cannot parse pattern '" + pattern + "'", var4);
@@ -786,18 +818,47 @@ public ExtendedPatternLayout.SerializerBuilder setNoConsoleNoAnsi(boolean noCons
this.noConsoleNoAnsi = noConsoleNoAnsi;
return this;
}
+
+ /**
+ * Sets whether to start byte array output on a new line.
+ *
+ * @param initNewLine Whether to initialize byte array output on a new line
+ * @return This builder instance
+ */
+ public ExtendedPatternLayout.SerializerBuilder setInitNewLine(boolean initNewLine) {
+ this.initNewLine = initNewLine;
+ return this;
+ }
+
+ /**
+ * Sets whether to format byte arrays with spaces between bytes for readability.
+ *
+ * @param prettyPrinting Whether to pretty print byte arrays
+ * @return This builder instance
+ */
+ public ExtendedPatternLayout.SerializerBuilder setPrettyPrinting(boolean prettyPrinting) {
+ this.prettyPrinting = prettyPrinting;
+ return this;
+ }
}
private static final class ExtendedPatternLayoutSerializer
implements AbstractStringLayout.Serializer, LocationAware {
private final PatternFormatter[] formatters;
private final RegexReplacement replace;
+ private final boolean initNewLine;
+ private final boolean prettyPrinting;
private ExtendedPatternLayoutSerializer(
- PatternFormatter[] formatters, RegexReplacement replace) {
+ PatternFormatter[] formatters,
+ RegexReplacement replace,
+ boolean initNewLine,
+ boolean prettyPrinting) {
super();
this.formatters = formatters;
this.replace = replace;
+ this.initNewLine = initNewLine;
+ this.prettyPrinting = prettyPrinting;
}
@Override
@@ -831,11 +892,13 @@ public String toSerializable(LogEvent event) {
*
*
*
- * The byte array formatting is controlled by two static configuration options:
+ *
The byte array formatting is controlled by two configuration options:
*
*
- * - {@link Builder#prettyPrinting} - Whether to format with spaces between bytes
- *
- {@link Builder#initNewLine} - Whether to start byte arrays on a new line
+ *
- {@link ExtendedPatternLayoutSerializer#prettyPrinting} - Whether to format with
+ * spaces between bytes
+ *
- {@link ExtendedPatternLayoutSerializer#initNewLine} - Whether to start byte arrays
+ * on a new line
*
*
* @param event The LogEvent to serialize
@@ -870,9 +933,7 @@ public StringBuilder toSerializable(LogEvent event, StringBuilder builder) {
builder.indexOf(Arrays.toString((byte[]) param))
+ Arrays.toString((byte[]) param).length(),
DataConverter.bytesToHexString(
- (byte[]) param,
- Builder.prettyPrinting,
- Builder.initNewLine));
+ (byte[]) param, prettyPrinting, initNewLine));
}
}
}
diff --git a/src/test/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayoutTest.java b/src/test/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayoutTest.java
index 8ccdea32..8d717a54 100644
--- a/src/test/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayoutTest.java
+++ b/src/test/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayoutTest.java
@@ -417,6 +417,8 @@ void testBuilderWithAllOptions() {
.withNoConsoleNoAnsi(true)
.withHeader(header)
.withFooter(footer)
+ .withInitNewLine(false)
+ .withPrettyPrinting(false)
.build();
assertNotNull(layout);
@@ -441,6 +443,8 @@ void testSerializerBuilderWithAllOptions() {
builder.setAlwaysWriteExceptions(true);
builder.setDisableAnsi(true);
builder.setNoConsoleNoAnsi(true);
+ builder.setInitNewLine(false);
+ builder.setPrettyPrinting(false);
AbstractStringLayout.Serializer serializer = builder.build();
assertNotNull(serializer);
diff --git a/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java b/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java
index 29e3d863..e9c8b605 100644
--- a/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java
+++ b/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java
@@ -21,6 +21,7 @@
import java.util.Random;
import org.junit.jupiter.api.Test;
+@SuppressWarnings("deprecation")
class ArrayConverterTest {
/** Test of longToUint64Bytes method, of class ArrayConverter. */
diff --git a/src/test/java/de/rub/nds/modifiablevariable/util/BadRandomTest.java b/src/test/java/de/rub/nds/modifiablevariable/util/BadRandomTest.java
index 88e327ef..b653b7bb 100644
--- a/src/test/java/de/rub/nds/modifiablevariable/util/BadRandomTest.java
+++ b/src/test/java/de/rub/nds/modifiablevariable/util/BadRandomTest.java
@@ -45,7 +45,7 @@ void testConstructorWithRandom() {
@Test
@SuppressWarnings("deprecation")
- static void testDeprecatedConstructorWithRandomAndSeed() {
+ void testDeprecatedConstructorWithRandomAndSeed() {
// Test that the deprecated constructor works
// Use a fresh Random for each BadRandom to ensure we're testing functionality
Random random1 = new Random(42);
@@ -72,7 +72,7 @@ static void testDeprecatedConstructorWithRandomAndSeed() {
@Test
@SuppressWarnings("deprecation")
- static void testDeprecatedConstructorWithRandomAndSpiAndProvider() {
+ void testDeprecatedConstructorWithRandomAndSpiAndProvider() {
// Test that the deprecated constructor works
Random random1 = new Random(42);
BadRandom badRandom = new BadRandom(random1, null, null);