Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.rub.nds</groupId>
<artifactId>protocol-toolkit-bom</artifactId>
<version>6.0.1</version>
<version>6.1.1</version>
</parent>

<artifactId>modifiable-variable</artifactId>
Expand Down Expand Up @@ -177,10 +177,20 @@
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgs>
<compilerArg>-proc:full</compilerArg>
</compilerArgs>
<proc>full</proc>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<compilerArgs>
<!-- The following arguments are required for Log4J plugins (ExtendedPatternLayout) since Log4J 2.25.0 -->
<arg>-Alog4j.graalvm.groupId=${project.groupId}</arg>
<arg>-Alog4j.graalvm.artifactId=${project.artifactId}</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<!-- Execute unit tests -->
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private ExtendedPatternLayout(
boolean disableAnsi,
boolean noConsoleNoAnsi,
String headerPattern,
String footerPattern) {
String footerPattern,
boolean initNewLine,
boolean prettyPrinting) {
super(
config,
charset,
Expand All @@ -113,6 +115,8 @@ private ExtendedPatternLayout(
.setDisableAnsi(disableAnsi)
.setNoConsoleNoAnsi(noConsoleNoAnsi)
.setPattern(headerPattern)
.setInitNewLine(initNewLine)
.setPrettyPrinting(prettyPrinting)
.build(),
newSerializerBuilder()
.setConfiguration(config)
Expand All @@ -122,6 +126,8 @@ private ExtendedPatternLayout(
.setDisableAnsi(disableAnsi)
.setNoConsoleNoAnsi(noConsoleNoAnsi)
.setPattern(footerPattern)
.setInitNewLine(initNewLine)
.setPrettyPrinting(prettyPrinting)
.build());
conversionPattern = eventPattern;
this.patternSelector = patternSelector;
Expand All @@ -135,6 +141,8 @@ private ExtendedPatternLayout(
.setNoConsoleNoAnsi(noConsoleNoAnsi)
.setPattern(eventPattern)
.setDefaultPattern("%m%n")
.setInitNewLine(initNewLine)
.setPrettyPrinting(prettyPrinting)
.build();
}

Expand Down Expand Up @@ -339,6 +347,8 @@ public static ExtendedPatternLayout createLayout(
.withNoConsoleNoAnsi(noConsoleNoAnsi)
.withHeader(headerPattern)
.withFooter(footerPattern)
.withInitNewLine(false)
.withPrettyPrinting(false)
.build();
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
*
Expand All @@ -565,7 +593,9 @@ public ExtendedPatternLayout build() {
disableAnsi,
noConsoleNoAnsi,
header,
footer);
footer,
initNewLine,
prettyPrinting);
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -831,11 +892,13 @@ public String toSerializable(LogEvent event) {
* </ul>
* </ol>
*
* <p>The byte array formatting is controlled by two static configuration options:
* <p>The byte array formatting is controlled by two configuration options:
*
* <ul>
* <li>{@link Builder#prettyPrinting} - Whether to format with spaces between bytes
* <li>{@link Builder#initNewLine} - Whether to start byte arrays on a new line
* <li>{@link ExtendedPatternLayoutSerializer#prettyPrinting} - Whether to format with
* spaces between bytes
* <li>{@link ExtendedPatternLayoutSerializer#initNewLine} - Whether to start byte arrays
* on a new line
* </ul>
*
* @param event The LogEvent to serialize
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ void testBuilderWithAllOptions() {
.withNoConsoleNoAnsi(true)
.withHeader(header)
.withFooter(footer)
.withInitNewLine(false)
.withPrettyPrinting(false)
.build();

assertNotNull(layout);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down