You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2024/01/09 20:19:26 UTC

(logging-log4j2) branch main updated (ec93d181c8 -> b1113c7833)

This is an automated email from the ASF dual-hosted git repository.

vy pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


    from ec93d181c8 Convert properties configuration file
     new 027009eeab Sync `JsonWriter` with the one in `2.x`
     new 923a43ef23 Fix `JsonTemplateLayoutConcurrentEncodeTest`
     new 3254858d6e Fix JTL nested logging test
     new b1113c7833 Fix static analysis issues

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../JsonTemplateLayoutConcurrentEncodeTest.java    | 44 ++++++++--------------
 ...stedLoggingTest.java => NestedLoggingTest.java} | 25 +++++-------
 .../template/json/resolver/LevelResolverTest.java  |  8 ++--
 .../json/resolver/MessageResolverTest.java         |  2 +-
 .../resolver/StackTraceStringResolverTest.java     |  1 +
 .../json/resolver/TimestampResolverTest.java       |  2 +-
 .../layout/template/json/util/JsonWriterTest.java  | 29 ++------------
 ...clerNestedLogging.xml => NestedLoggingTest.xml} |  2 +-
 .../json/resolver/MessageResolverFactory.java      |  2 +-
 .../layout/template/json/util/JsonWriter.java      | 21 +++++------
 10 files changed, 48 insertions(+), 88 deletions(-)
 rename log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/{ThreadLocalRecyclerNestedLoggingTest.java => NestedLoggingTest.java} (70%)
 rename log4j-layout-template-json-test/src/test/resources/{threadLocalRecyclerNestedLogging.xml => NestedLoggingTest.xml} (95%)


(logging-log4j2) 04/04: Fix static analysis issues

Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit b1113c78337edc4a04a0d4225a7d7220b4726a54
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Jan 9 21:19:44 2024 +0100

    Fix static analysis issues
---
 .../layout/template/json/NestedLoggingTest.java    |  4 +++
 .../template/json/resolver/LevelResolverTest.java  |  8 +++---
 .../json/resolver/MessageResolverTest.java         |  2 +-
 .../resolver/StackTraceStringResolverTest.java     |  1 +
 .../json/resolver/TimestampResolverTest.java       |  2 +-
 .../layout/template/json/util/JsonWriterTest.java  | 29 +++-------------------
 .../json/resolver/MessageResolverFactory.java      |  2 +-
 .../layout/template/json/util/JsonWriter.java      |  2 +-
 8 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java
index 284dc0c113..eb40af00f6 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.layout.template.json;
 
+import java.io.Serial;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -37,6 +38,9 @@ public class NestedLoggingTest {
 
     private static final class ThrowableLoggingInGetMessage extends RuntimeException {
 
+        @Serial
+        private static final long serialVersionUID = 42L;
+
         private final Logger logger;
 
         private ThrowableLoggingInGetMessage(final Logger logger) {
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/LevelResolverTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/LevelResolverTest.java
index d4d3257349..80fab00497 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/LevelResolverTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/LevelResolverTest.java
@@ -16,12 +16,13 @@
  */
 package org.apache.logging.log4j.layout.template.json.resolver;
 
-import static org.apache.logging.log4j.layout.template.json.TestHelpers.*;
+import static org.apache.logging.log4j.layout.template.json.TestHelpers.CONFIGURATION;
+import static org.apache.logging.log4j.layout.template.json.TestHelpers.asMap;
+import static org.apache.logging.log4j.layout.template.json.TestHelpers.usingSerializedLogEventAccessor;
+import static org.apache.logging.log4j.layout.template.json.TestHelpers.writeJson;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout;
@@ -46,7 +47,6 @@ class LevelResolverTest {
                 .build();
 
         // Create the log event.
-        final Marker marker = MarkerManager.getMarker("MARKER");
         Level level = Level.forName("CUSTOM_LEVEL", 250);
         final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(level).build();
 
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverTest.java
index d4efb87e30..f5553d85e4 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverTest.java
@@ -43,7 +43,7 @@ import org.junit.jupiter.api.Test;
 class MessageResolverTest {
 
     /**
-     * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-3080">LOG4J2-3080</a>
+     * Tests the inconsistent <code>fallbackKey</code> behaviour described in <a href="https://issues.apache.org/jira/browse/LOG4J2-3080">LOG4J2-3080</a>.
      */
     @Test
     @LoggerContextSource("messageFallbackKeyUsingJsonTemplateLayout.xml")
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/StackTraceStringResolverTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/StackTraceStringResolverTest.java
index 02564b3c7f..ec2c6d348d 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/StackTraceStringResolverTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/StackTraceStringResolverTest.java
@@ -39,6 +39,7 @@ import org.assertj.core.api.AbstractStringAssert;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
+@SuppressWarnings("StaticAssignmentOfThrowable")
 class StackTraceStringResolverTest {
 
     ////////////////////////////////////////////////////////////////////////////
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolverTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolverTest.java
index 71ebc304d9..ee55cba480 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolverTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolverTest.java
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
 class TimestampResolverTest {
 
     /**
-     * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-3183">LOG4J2-3183</a>
+     * Tests epoch nanoseconds do not overlap as reported in <a href="https://issues.apache.org/jira/browse/LOG4J2-3183">LOG4J2-3183</a>.
      */
     @Test
     void epoch_nanos_should_not_overlap() {
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java
index b121360095..9529bcbc42 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java
@@ -433,12 +433,7 @@ class JsonWriterTest {
     void test_writeString_emitter_excessive_string_ending_with_high_surrogate() {
         withLockedWriter(writer -> {
             final int maxStringLength = writer.getMaxStringLength();
-            @SuppressWarnings("StringBufferReplaceableByString")
-            final String excessiveString = new StringBuilder()
-                    .append("x".repeat(maxStringLength - 1))
-                    .append(HI_SURROGATE)
-                    .append(LO_SURROGATE)
-                    .toString();
+            final String excessiveString = "x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE;
             final String expectedJson =
                     "\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
             final BiConsumer<StringBuilder, String> emitter = StringBuilder::append;
@@ -479,12 +474,7 @@ class JsonWriterTest {
     void test_writeString_formattable_excessive_string_ending_with_high_surrogate() {
         withLockedWriter(writer -> {
             final int maxStringLength = writer.getMaxStringLength();
-            @SuppressWarnings("StringBufferReplaceableByString")
-            final String excessiveString = new StringBuilder()
-                    .append("x".repeat(maxStringLength - 1))
-                    .append(HI_SURROGATE)
-                    .append(LO_SURROGATE)
-                    .toString();
+            final String excessiveString = "x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE;
             final String expectedJson =
                     "\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
             final String actualJson =
@@ -549,12 +539,7 @@ class JsonWriterTest {
     void test_writeString_excessive_seq_ending_with_high_surrogate() {
         withLockedWriter(writer -> {
             final int maxStringLength = writer.getMaxStringLength();
-            @SuppressWarnings("StringBufferReplaceableByString")
-            final CharSequence seq = new StringBuilder()
-                    .append("x".repeat(maxStringLength - 1))
-                    .append(HI_SURROGATE)
-                    .append(LO_SURROGATE)
-                    .toString();
+            final CharSequence seq = "x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE;
             final String expectedJson =
                     "\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
             final String actualJson = writer.use(() -> writer.writeString(seq));
@@ -614,13 +599,7 @@ class JsonWriterTest {
     void test_writerString_excessive_buffer_ending_with_high_surrogate() {
         withLockedWriter(writer -> {
             final int maxStringLength = writer.getMaxStringLength();
-            @SuppressWarnings("StringBufferReplaceableByString")
-            final char[] buffer = new StringBuilder()
-                    .append("x".repeat(maxStringLength - 1))
-                    .append(HI_SURROGATE)
-                    .append(LO_SURROGATE)
-                    .toString()
-                    .toCharArray();
+            final char[] buffer = ("x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE).toCharArray();
             final String expectedJson =
                     "\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
             final String actualJson = writer.use(() -> writer.writeString(buffer));
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverFactory.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverFactory.java
index cca3b9c93c..bcdfd01536 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverFactory.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverFactory.java
@@ -21,7 +21,7 @@ import org.apache.logging.log4j.plugins.Plugin;
 import org.apache.logging.log4j.plugins.PluginFactory;
 
 /**
- * @see MessageResolver
+ * A {@link MessageResolver} factory.
  */
 @Namespace(TemplateResolverFactory.CATEGORY)
 @Plugin("MessageResolverFactory")
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
index 9b9aa4ebd4..4316d731fd 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
@@ -700,7 +700,7 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
         } else {
             final long longNumber = number.longValue();
             final double doubleValue = number.doubleValue();
-            if (Double.compare(longNumber, doubleValue) == 0) {
+            if (Double.compare((double) longNumber, doubleValue) == 0) {
                 writeNumber(longNumber);
             } else {
                 writeNumber(doubleValue);


(logging-log4j2) 01/04: Sync `JsonWriter` with the one in `2.x`

Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 027009eeab786340ce099d399d275d23732074fc
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Jan 9 13:05:19 2024 +0100

    Sync `JsonWriter` with the one in `2.x`
---
 .../log4j/layout/template/json/util/JsonWriter.java   | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
index 765fcdf8e2..9b9aa4ebd4 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
@@ -24,7 +24,6 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.function.BiConsumer;
 import org.apache.logging.log4j.util.IndexedReadOnlyStringMap;
-import org.apache.logging.log4j.util.Lazy;
 import org.apache.logging.log4j.util.StringBuilderFormattable;
 import org.apache.logging.log4j.util.StringMap;
 
@@ -66,7 +65,9 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
      * character to use after backslash; and negative values, that generic
      * (backslash - u) escaping is to be used.
      */
-    private static final Lazy<int[]> ESC_CODES = Lazy.pure(() -> {
+    private static final int[] ESC_CODES;
+
+    static {
         final int[] table = new int[128];
         // Control chars need generic escape sequence
         for (int i = 0; i < 32; ++i) {
@@ -82,8 +83,8 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
         table[0x0C] = 'f';
         table[0x0A] = 'n';
         table[0x0D] = 'r';
-        return table;
-    });
+        ESC_CODES = table;
+    }
 
     private final char[] quoteBuffer;
 
@@ -582,12 +583,11 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
                 length > 0 && Character.isHighSurrogate(seq.charAt(offset + length - 1)) ? -1 : 0;
         final int limit = offset + length + surrogateCorrection;
         int i = offset;
-        final int[] escCodes = ESC_CODES.get();
         outer:
         while (i < limit) {
             while (true) {
                 final char c = seq.charAt(i);
-                if (c < escCodes.length && escCodes[c] != 0) {
+                if (c < ESC_CODES.length && ESC_CODES[c] != 0) {
                     break;
                 }
                 stringBuilder.append(c);
@@ -596,7 +596,7 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
                 }
             }
             final char d = seq.charAt(i++);
-            final int escCode = escCodes[d];
+            final int escCode = ESC_CODES[d];
             final int quoteBufferLength = escCode < 0 ? quoteNumeric(d) : quoteNamed(escCode);
             stringBuilder.append(quoteBuffer, 0, quoteBufferLength);
         }
@@ -646,12 +646,11 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
         final int surrogateCorrection = length > 0 && Character.isHighSurrogate(buffer[offset + length - 1]) ? -1 : 0;
         final int limit = offset + length + surrogateCorrection;
         int i = offset;
-        final int[] escCodes = ESC_CODES.get();
         outer:
         while (i < limit) {
             while (true) {
                 final char c = buffer[i];
-                if (c < escCodes.length && escCodes[c] != 0) {
+                if (c < ESC_CODES.length && ESC_CODES[c] != 0) {
                     break;
                 }
                 stringBuilder.append(c);
@@ -660,7 +659,7 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
                 }
             }
             final char d = buffer[i++];
-            final int escCode = escCodes[d];
+            final int escCode = ESC_CODES[d];
             final int quoteBufferLength = escCode < 0 ? quoteNumeric(d) : quoteNamed(escCode);
             stringBuilder.append(quoteBuffer, 0, quoteBufferLength);
         }


(logging-log4j2) 02/04: Fix `JsonTemplateLayoutConcurrentEncodeTest`

Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 923a43ef2365baf44a80c668be2b364a532b49d1
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Jan 9 13:08:47 2024 +0100

    Fix `JsonTemplateLayoutConcurrentEncodeTest`
---
 .../JsonTemplateLayoutConcurrentEncodeTest.java    | 44 ++++++++--------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java
index 2e9c6973aa..bce72ccc41 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java
@@ -20,7 +20,12 @@ import static org.apache.logging.log4j.layout.template.json.TestHelpers.asMap;
 import static org.apache.logging.log4j.layout.template.json.TestHelpers.writeJson;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -38,10 +43,9 @@ import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
 import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.layout.StringBuilderEncoder;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.parallel.Execution;
 import org.junit.jupiter.api.parallel.ExecutionMode;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Tests {@link JsonTemplateLayout} doesn't exhibit unexpected behavior when accessed concurrently.
@@ -58,21 +62,14 @@ import org.junit.jupiter.params.provider.ValueSource;
 @Execution(ExecutionMode.SAME_THREAD)
 class JsonTemplateLayoutConcurrentEncodeTest {
 
-    @ParameterizedTest
-    @ValueSource(
-            strings = {
-                "dummy",
-                "threadLocal",
-                "queue:supplier=java.util.concurrent.ArrayBlockingQueue.new",
-                "queue:supplier=org.jctools.queues.MpmcArrayQueue.new"
-            })
-    void test_concurrent_encode(final String recyclerFactory) throws IOException {
-        final Path appenderFilepath = createAppenderFilepath(recyclerFactory);
+    @Test
+    void test_concurrent_encode() throws IOException {
+        final Path appenderFilepath = createAppenderFilepath();
         final int workerCount = 10;
         final int messageLength = 1_000;
         final int messageCount = 1_000;
         try {
-            withContextFromTemplate(appenderFilepath, recyclerFactory, loggerContext -> {
+            withContextFromTemplate(appenderFilepath, loggerContext -> {
                 final Logger logger = loggerContext.getLogger(JsonTemplateLayoutConcurrentEncodeTest.class);
                 runWorkers(workerCount, messageLength, messageCount, logger);
             });
@@ -84,24 +81,16 @@ class JsonTemplateLayoutConcurrentEncodeTest {
         Files.delete(appenderFilepath);
     }
 
-    private static Path createAppenderFilepath(final String recyclerFactory) {
-        final String appenderFilename = String.format(
-                "%s-%s.log",
-                JsonTemplateLayoutConcurrentEncodeTest.class.getSimpleName(),
-                recyclerFactory.replaceAll("[^A-Za-z0-9]+", ""));
+    private static Path createAppenderFilepath() {
+        final String appenderFilename = JsonTemplateLayoutConcurrentEncodeTest.class.getSimpleName() + ".log";
         return Paths.get(System.getProperty("java.io.tmpdir"), appenderFilename);
     }
 
     private static void withContextFromTemplate(
-            final Path appenderFilepath,
-            final String recyclerFactory,
-            final Consumer<LoggerContext> loggerContextConsumer) {
+            final Path appenderFilepath, final Consumer<LoggerContext> loggerContextConsumer) {
 
         // Create the configuration builder.
-        final String configName = String.format(
-                "%s-%s",
-                JsonTemplateLayoutConcurrentEncodeTest.class.getSimpleName(),
-                recyclerFactory.replaceAll("[^A-Za-z0-9]+", ""));
+        final String configName = JsonTemplateLayoutConcurrentEncodeTest.class.getSimpleName();
         final ConfigurationBuilder<?> configBuilder = ConfigurationBuilderFactory.newConfigurationBuilder()
                 .setStatusLevel(Level.ERROR)
                 .setConfigurationName(configName);
@@ -120,8 +109,7 @@ class JsonTemplateLayoutConcurrentEncodeTest {
                         .addAttribute("ignoreExceptions", false)
                         .add(configBuilder
                                 .newLayout("JsonTemplateLayout")
-                                .addAttribute("eventTemplate", eventTemplateJson)
-                                .addAttribute("recyclerFactory", recyclerFactory)))
+                                .addAttribute("eventTemplate", eventTemplateJson)))
                 .add(configBuilder.newRootLogger(Level.ALL).add(configBuilder.newAppenderRef(appenderName)))
                 .build(false);
 


(logging-log4j2) 03/04: Fix JTL nested logging test

Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 3254858d6e102464f7afb9c302542e9afffa3cd3
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Jan 9 13:05:39 2024 +0100

    Fix JTL nested logging test
---
 ...estedLoggingTest.java => NestedLoggingTest.java} | 21 +++++----------------
 ...yclerNestedLogging.xml => NestedLoggingTest.xml} |  2 +-
 2 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/ThreadLocalRecyclerNestedLoggingTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java
similarity index 70%
rename from log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/ThreadLocalRecyclerNestedLoggingTest.java
rename to log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java
index c9a5ac27ca..284dc0c113 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/ThreadLocalRecyclerNestedLoggingTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java
@@ -25,19 +25,15 @@ import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.test.appender.ListAppender;
 import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
 import org.apache.logging.log4j.core.test.junit.Named;
-import org.apache.logging.log4j.internal.recycler.ThreadLocalRecyclerFactoryProvider;
-import org.apache.logging.log4j.spi.LoggingSystemProperty;
 import org.assertj.core.api.Assertions;
 import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
 
 /**
- * Tests if logging while trying to encode an event causes thread local recycler to incorrectly share buffers and end up overriding layout's earlier encoding work.
+ * Tests if logging while trying to encode an event causes the default recycler to incorrectly share buffers and end up overriding layout's earlier encoding work.
  *
  * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2368">LOG4J2-2368</a>
  */
-@SetSystemProperty(key = LoggingSystemProperty.Constant.RECYCLER_FACTORY_PROPERTY, value = "threadLocal")
-public class ThreadLocalRecyclerNestedLoggingTest {
+public class NestedLoggingTest {
 
     private static final class ThrowableLoggingInGetMessage extends RuntimeException {
 
@@ -55,21 +51,14 @@ public class ThreadLocalRecyclerNestedLoggingTest {
     }
 
     @Test
-    @LoggerContextSource("threadLocalRecyclerNestedLogging.xml")
-    public void nested_logging_should_not_pollute_thread_local(
+    @LoggerContextSource("NestedLoggingTest.xml")
+    public void nested_logging_should_work(
             final LoggerContext loggerContext,
             final @Named(value = "List1") ListAppender appender1,
             final @Named(value = "List2") ListAppender appender2) {
 
-        // Verify the recycler factory type
-        final String actualRecyclerFactoryClassName =
-                loggerContext.getConfiguration().getRecyclerFactory().getClass().getCanonicalName();
-        final String expectedRecyclerFactoryClassName =
-                ThreadLocalRecyclerFactoryProvider.class.getCanonicalName() + ".ThreadLocalRecyclerFactory";
-        Assertions.assertThat(actualRecyclerFactoryClassName).isEqualTo(expectedRecyclerFactoryClassName);
-
         // Perform nested logging
-        final Logger logger = loggerContext.getLogger(ThreadLocalRecyclerNestedLoggingTest.class);
+        final Logger logger = loggerContext.getLogger(NestedLoggingTest.class);
         logger.error("A", new ThrowableLoggingInGetMessage(logger));
 
         // Collect logged messages
diff --git a/log4j-layout-template-json-test/src/test/resources/threadLocalRecyclerNestedLogging.xml b/log4j-layout-template-json-test/src/test/resources/NestedLoggingTest.xml
similarity index 95%
rename from log4j-layout-template-json-test/src/test/resources/threadLocalRecyclerNestedLogging.xml
rename to log4j-layout-template-json-test/src/test/resources/NestedLoggingTest.xml
index a5394bbf9f..cc5d2df8ce 100644
--- a/log4j-layout-template-json-test/src/test/resources/threadLocalRecyclerNestedLogging.xml
+++ b/log4j-layout-template-json-test/src/test/resources/NestedLoggingTest.xml
@@ -15,7 +15,7 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
-<Configuration status="OFF" name="ThreadLocalRecyclerNestedLoggingTest">
+<Configuration status="OFF" name="NestedLoggingTest">
   <Properties>
     <Property name="eventTemplate">[{"$resolver": "message", "stringified": true}, {"$resolver": "exception", "field": "message"}]</Property>
   </Properties>