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 2023/11/22 12:11:01 UTC
(logging-log4j2) 12/13: Remove `log4j-layout-jackson-json`
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch module-deletion
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit e45c66a2828470d081e372c4185a98d08e123d36
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Nov 22 11:17:55 2023 +0100
Remove `log4j-layout-jackson-json`
---
log4j-core-its/pom.xml | 2 +-
.../log4j/core/appender/HttpAppenderTest.java | 16 +-
.../appender/JsonCompleteFileAppenderTest.java | 111 ----
.../log4j/core/appender/SocketAppenderTest.java | 121 ++--
.../log4j/core/test/categories/Layouts.java | 4 -
.../src/main/resources/Log4j-config.xsd | 11 -
.../resources/JsonCompleteFileAppenderTest.xml | 30 -
.../src/test/resources/log4j-socket-options.xml | 2 +-
.../test/resources/log4j-ssl-socket-options.xml | 2 +-
.../src/test/resources/log4j2-json-layout.xml | 30 -
log4j-core/src/main/resources/Log4j-config.xsd | 11 -
log4j-distribution/pom.xml | 12 -
log4j-layout-jackson-json/pom.xml | 106 ----
.../jackson/json/JsonSetupContextInitializer.java | 70 ---
.../log4j/jackson/json/Log4jJsonModule.java | 61 --
.../log4j/jackson/json/Log4jJsonObjectMapper.java | 55 --
.../jackson/json/layout/JsonJacksonFactory.java | 87 ---
.../log4j/jackson/json/layout/JsonLayout.java | 322 ----------
.../log4j/jackson/json/layout/package-info.java | 22 -
.../logging/log4j/jackson/json/package-info.java | 22 -
.../jackson/json/parser/JsonLogEventParser.java | 31 -
.../log4j/jackson/json/parser/package-info.java | 22 -
.../jackson/json/JacksonIssue429MyNamesTest.java | 128 ----
.../log4j/jackson/json/JacksonIssue429Test.java | 92 ---
.../log4j/jackson/json/LevelMixInJsonTest.java | 28 -
.../log4j/jackson/json/MarkerMixInJsonTest.java | 28 -
.../json/StackTraceElementJsonMixInTest.java | 87 ---
.../ConcurrentLoggingWithJsonLayoutTest.java | 112 ----
.../jackson/json/layout/JsonLayoutMillisTest.java | 72 ---
.../log4j/jackson/json/layout/JsonLayoutTest.java | 694 ---------------------
.../json/layout/ThrowableProxyJsonTest.java | 30 -
.../json/parser/JsonLogEventParserTest.java | 129 ----
.../resources/log4j2-json-layout-timestamp.xml | 30 -
.../src/test/resources/log4j2-json-layout.xml | 30 -
.../jackson/xml/StackTraceElementXmlMixInTest.java | 2 +-
log4j-layout-template-json-test/pom.xml | 6 -
.../log4j/layout/template/json/EcsLayoutTest.java | 3 +-
.../log4j/layout/template/json/JsonLayoutTest.java | 87 ---
.../log4j/layout/template/json/LogstashIT.java | 3 +
.../log4j/layout/template/json/util/UrisTest.java | 2 +-
.../layout/template/json/JsonTemplateLayout.java | 6 +
.../src/main/resources/JsonLayout.json | 87 ---
log4j-perf/pom.xml | 4 -
.../template/json/JsonTemplateLayoutBenchmark.java | 30 -
.../json/JsonTemplateLayoutBenchmarkState.java | 46 --
pom.xml | 15 +-
src/site/asciidoc/manual/appenders.adoc | 6 +-
.../asciidoc/manual/json-template-layout.adoc.vm | 23 +-
src/site/asciidoc/manual/layouts.adoc | 185 +-----
src/site/asciidoc/manual/lookups.adoc | 10 +-
src/site/asciidoc/runtime-dependencies.adoc | 3 -
src/site/site.xml | 1 -
52 files changed, 121 insertions(+), 3008 deletions(-)
diff --git a/log4j-core-its/pom.xml b/log4j-core-its/pom.xml
index 2e572bf66a..c845432d19 100644
--- a/log4j-core-its/pom.xml
+++ b/log4j-core-its/pom.xml
@@ -117,7 +117,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson-json</artifactId>
+ <artifactId>log4j-layout-template-json</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
index d8b1a68ddc..3c5ae8a118 100644
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
+++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
@@ -42,7 +42,7 @@ import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
import org.apache.logging.log4j.core.net.ssl.TrustStoreConfiguration;
import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
import org.apache.logging.log4j.core.test.net.ssl.TestConstants;
-import org.apache.logging.log4j.jackson.json.layout.JsonLayout;
+import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.status.StatusData;
import org.apache.logging.log4j.status.StatusListener;
@@ -166,7 +166,7 @@ public class HttpAppenderTest {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
.build();
@@ -184,7 +184,7 @@ public class HttpAppenderTest {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setUrl(new URL("https://localhost:" + wireMockRule.httpsPort() + "/test/log4j/"))
.setSslConfiguration(SslConfiguration.createSSLConfiguration(
@@ -219,7 +219,7 @@ public class HttpAppenderTest {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setMethod("PUT")
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/1234"))
@@ -238,7 +238,7 @@ public class HttpAppenderTest {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
.setHeaders(new Property[] {
@@ -281,7 +281,7 @@ public class HttpAppenderTest {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
.build();
@@ -304,7 +304,7 @@ public class HttpAppenderTest {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setIgnoreExceptions(false)
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
@@ -316,7 +316,7 @@ public class HttpAppenderTest {
public void testAppendConnectError() throws Exception {
final Appender appender = HttpAppender.newBuilder()
.setName("Http")
- .setLayout(JsonLayout.createDefaultLayout())
+ .setLayout(JsonTemplateLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setIgnoreExceptions(false)
.setUrl(new URL("http://localhost:" + (wireMockRule.port() + 1) + "/test/log4j/"))
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java
deleted file mode 100644
index bf52622a32..0000000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.appender;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.util.List;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.selector.ContextSelector;
-import org.apache.logging.log4j.core.selector.CoreContextSelectors;
-import org.apache.logging.log4j.core.test.categories.Layouts;
-import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.apache.logging.log4j.core.test.util.FixedTimeClock;
-import org.apache.logging.log4j.test.junit.CleanFiles;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.RuleChain;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-/**
- * Tests a "complete" JSON file.
- */
-@RunWith(Parameterized.class)
-@Category(Layouts.Json.class)
-public class JsonCompleteFileAppenderTest {
-
- public JsonCompleteFileAppenderTest(final Class<ContextSelector> contextSelector) {
- this.loggerContextRule = new LoggerContextRule("JsonCompleteFileAppenderTest.xml", contextSelector);
- this.cleanFiles = new CleanFiles(logFile);
- this.ruleChain = RuleChain.outerRule(cleanFiles).around(loggerContextRule);
- }
-
- @BeforeClass
- public static void beforeClass() {
- System.setProperty(Log4jPropertyKey.CONFIG_CLOCK.getKey(), FixedTimeClock.class.getName());
- }
-
- @AfterClass
- public static void afterClass() {
- System.clearProperty(Log4jPropertyKey.CONFIG_CLOCK.getKey());
- }
-
- @Parameters(name = "{0}")
- public static Class<?>[] getParameters() {
- return CoreContextSelectors.CLASSES;
- }
-
- private final File logFile = new File("target", "JsonCompleteFileAppenderTest.log");
- private final LoggerContextRule loggerContextRule;
- private final CleanFiles cleanFiles;
-
- @Rule
- public RuleChain ruleChain;
-
- @Test
- public void testFlushAtEndOfBatch() throws Exception {
- final Logger logger = this.loggerContextRule.getLogger("com.foo.Bar");
- final String logMsg = "Message flushed with immediate flush=true";
- logger.info(logMsg);
- logger.error(logMsg, new IllegalArgumentException("badarg"));
- this.loggerContextRule.getLoggerContext().stop(); // stops async thread
-
- final List<String> lines = Files.readAllLines(logFile.toPath(), Charset.forName("UTF8"));
-
- final String[] expected = {
- "[", // equals
- "{", // equals
- " \"thread\" : \"main\",", //
- " \"level\" : \"INFO\",", //
- " \"loggerName\" : \"com.foo.Bar\",", //
- " \"message\" : \"Message flushed with immediate flush=true\",", //
- " \"endOfBatch\" : false,", //
- " \"loggerFqcn\" : \"org.apache.logging.log4j.spi.AbstractLogger\",", //
- " \"instant\" : {", //
- " \"epochSecond\" : 1234567,", //
- " \"nanoOfSecond\" : 890000000", //
- " },", //
- };
- for (int i = 0; i < expected.length; i++) {
- final String line = lines.get(i);
- assertTrue(
- "line " + i + " incorrect: [" + line + "], does not contain: [" + expected[i] + ']',
- line.contains(expected[i]));
- }
- final String location = "testFlushAtEndOfBatch";
- assertTrue("no location", !lines.get(0).contains(location));
- }
-}
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
index dbd230485b..6ea3bdfd91 100644
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
+++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
@@ -16,9 +16,11 @@
*/
package org.apache.logging.log4j.core.appender;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
-import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.EOFException;
import java.io.IOException;
@@ -27,6 +29,8 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
@@ -37,17 +41,13 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LoggingException;
import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.*;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.net.Protocol;
import org.apache.logging.log4j.core.test.AvailablePortFinder;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.Throwables;
-import org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper;
-import org.apache.logging.log4j.jackson.json.layout.JsonLayout;
+import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -68,6 +68,51 @@ public class SocketAppenderTest {
private static TcpSocketTestServer tcpServer;
private static UdpSocketTestServer udpServer;
+ private static final Layout LAYOUT = JsonTemplateLayout.newBuilder()
+ .setConfiguration(new DefaultConfiguration())
+ .setEventTemplate(LogEventDto.JSON_TEMPLATE)
+ .build();
+
+ public static final class LogEventDto {
+
+ private static final String JSON_TEMPLATE = ("{" + "'message': {'$resolver': 'message', 'stringified': true},"
+ + "'contextData': {'$resolver': 'mdc'},"
+ + "'contextStack': {'$resolver': 'ndc'},"
+ + "'error': {'$resolver': 'exception', 'field': 'message'}"
+ + "}")
+ .replaceAll("'", "\"");
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ private final String message;
+
+ private final Map<String, String> contextData;
+
+ private final List<String> contextStack;
+
+ private final String error;
+
+ @JsonCreator
+ public LogEventDto(
+ @JsonProperty("message") final String message,
+ @JsonProperty("contextData") final Map<String, String> contextData,
+ @JsonProperty("contextStack") final List<String> contextStack,
+ @JsonProperty("error") final String error) {
+ this.message = message;
+ this.contextData = contextData;
+ this.contextStack = contextStack;
+ this.error = error;
+ }
+
+ private static LogEventDto fromJsonBytes(final byte[] jsonBytes) throws IOException {
+ return MAPPER.readValue(jsonBytes, LogEventDto.class);
+ }
+
+ private static Iterator<LogEventDto> fromJsonByteStream(final InputStream stream) throws IOException {
+ return MAPPER.readerFor(LogEventDto.class).readValues(stream);
+ }
+ }
+
private final LoggerContext context = LoggerContext.getContext();
private final Logger logger = context.getLogger(SocketAppenderTest.class.getName());
@@ -130,7 +175,7 @@ public class SocketAppenderTest {
.setName("test")
.setImmediateFail(false)
.setBufferSize(bufferSize)
- .setLayout(JsonLayout.newBuilder().setProperties(true).build())
+ .setLayout(LAYOUT)
.build();
// @formatter:on
appender.start();
@@ -155,29 +200,28 @@ public class SocketAppenderTest {
ThreadContext.pop();
}
Thread.sleep(250);
- LogEvent event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
+ LogEventDto event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull(event, "No event retrieved");
- assertEquals("This is a test message", event.getMessage().getFormattedMessage(), "Incorrect event");
+ assertEquals("This is a test message", event.message, "Incorrect event");
assertTrue(tcpTestServer.getCount() > 0, "Message not delivered via TCP");
- assertEquals(expectedUuidStr, event.getContextData().getValue(tcKey));
+ assertEquals(expectedUuidStr, event.contextData.get(tcKey));
event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull(event, "No event retrieved");
- assertTrue(event.getMessage().getFormattedMessage().equals("Throwing an exception"), "Incorrect event");
+ assertEquals("Throwing an exception", event.message, "Incorrect event");
assertTrue(tcpTestServer.getCount() > 1, "Message not delivered via TCP");
- assertEquals(expectedUuidStr, event.getContextStack().pop());
- assertNotNull(event.getThrownProxy());
- assertEquals(expectedExMsg, event.getThrownProxy().getMessage());
+ assertThat(event.contextStack).containsOnly(expectedUuidStr);
+ assertEquals(expectedExMsg, event.error);
}
@Test
- public void testDefaultProtocol() throws Exception {
+ public void testDefaultProtocol() {
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
.setPort(tcpServer.getLocalPort())
.setReconnectDelayMillis(-1)
.setName("test")
.setImmediateFail(false)
- .setLayout(JsonLayout.newBuilder().setProperties(true).build())
+ .setLayout(LAYOUT)
.build();
// @formatter:on
assertNotNull(appender);
@@ -186,11 +230,8 @@ public class SocketAppenderTest {
@Test
public void testUdpAppender() throws Exception {
- try {
- udpServer.latch.await();
- } catch (final InterruptedException ex) {
- ex.printStackTrace();
- }
+ final boolean released = udpServer.latch.await(3, TimeUnit.SECONDS);
+ assertTrue(released);
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
@@ -199,7 +240,7 @@ public class SocketAppenderTest {
.setReconnectDelayMillis(-1)
.setName("test")
.setImmediateFail(false)
- .setLayout(JsonLayout.newBuilder().setProperties(true).build())
+ .setLayout(LAYOUT)
.build();
// @formatter:on
appender.start();
@@ -209,9 +250,9 @@ public class SocketAppenderTest {
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
logger.debug("This is a udp message");
- final LogEvent event = udpServer.getQueue().poll(3, TimeUnit.SECONDS);
+ final LogEventDto event = udpServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull(event, "No event retrieved");
- assertTrue(event.getMessage().getFormattedMessage().equals("This is a udp message"), "Incorrect event");
+ assertEquals("This is a udp message", event.message, "Incorrect event");
assertTrue(udpServer.getCount() > 0, "Message not delivered via UDP");
}
@@ -225,7 +266,7 @@ public class SocketAppenderTest {
.setReconnectDelayMillis(100)
.setName("test")
.setImmediateFail(false)
- .setLayout(JsonLayout.newBuilder().setProperties(true).build())
+ .setLayout(LAYOUT)
.build();
// @formatter:on
appender.start();
@@ -240,7 +281,7 @@ public class SocketAppenderTest {
logger.debug("This message is written because a deadlock never.");
- final LogEvent event = tcpSocketServer.getQueue().poll(3, TimeUnit.SECONDS);
+ final LogEventDto event = tcpSocketServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull(event, "No event retrieved");
} finally {
tcpSocketServer.shutdown();
@@ -248,7 +289,7 @@ public class SocketAppenderTest {
}
@Test
- public void testTcpAppenderNoWait() throws Exception {
+ public void testTcpAppenderNoWait() {
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
.setHost("localhost")
@@ -257,7 +298,7 @@ public class SocketAppenderTest {
.setName("test")
.setImmediateFail(false)
.setIgnoreExceptions(false)
- .setLayout(JsonLayout.newBuilder().setProperties(true).build())
+ .setLayout(LAYOUT)
.build();
// @formatter:on
appender.start();
@@ -276,8 +317,7 @@ public class SocketAppenderTest {
private Thread thread;
private final CountDownLatch latch = new CountDownLatch(1);
private final AtomicInteger count = new AtomicInteger();
- private final BlockingQueue<LogEvent> queue;
- private final ObjectMapper objectMapper = new Log4jJsonObjectMapper();
+ private final BlockingQueue<LogEventDto> queue;
public UdpSocketTestServer() throws IOException {
this.sock = new DatagramSocket(PORT);
@@ -309,7 +349,7 @@ public class SocketAppenderTest {
latch.countDown();
sock.receive(packet);
count.incrementAndGet();
- final LogEvent event = objectMapper.readValue(packet.getData(), Log4jLogEvent.class);
+ final LogEventDto event = LogEventDto.fromJsonBytes(packet.getData());
queue.add(event);
}
} catch (final Throwable e) {
@@ -324,7 +364,7 @@ public class SocketAppenderTest {
return count.get();
}
- public BlockingQueue<LogEvent> getQueue() {
+ public BlockingQueue<LogEventDto> getQueue() {
return queue;
}
}
@@ -334,8 +374,7 @@ public class SocketAppenderTest {
private final ServerSocket serverSocket;
private volatile boolean shutdown = false;
private final AtomicInteger count = new AtomicInteger();
- private final BlockingQueue<LogEvent> queue;
- private final ObjectMapper objectMapper = new Log4jJsonObjectMapper();
+ private final BlockingQueue<LogEventDto> queue;
@SuppressWarnings("resource")
public TcpSocketTestServer(final int port) throws IOException {
@@ -373,10 +412,10 @@ public class SocketAppenderTest {
if (socket != null) {
final InputStream is = socket.getInputStream();
while (!shutdown) {
- final MappingIterator<LogEvent> mappingIterator =
- objectMapper.readerFor(Log4jLogEvent.class).readValues(is);
- while (mappingIterator.hasNextValue()) {
- queue.add(mappingIterator.nextValue());
+ final Iterator<LogEventDto> it = LogEventDto.fromJsonByteStream(is);
+ while (it.hasNext()) {
+ final LogEventDto logEvent = it.next();
+ queue.add(logEvent);
count.incrementAndGet();
}
}
@@ -391,7 +430,7 @@ public class SocketAppenderTest {
}
}
- public BlockingQueue<LogEvent> getQueue() {
+ public BlockingQueue<LogEventDto> getQueue() {
return queue;
}
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Layouts.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Layouts.java
index 0cdc8b4540..4dcb2ca554 100644
--- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Layouts.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Layouts.java
@@ -24,9 +24,5 @@ public interface Layouts {
interface Jansi {}
- interface Json {}
-
interface Xml {}
-
- interface Yaml {}
}
diff --git a/log4j-core-test/src/main/resources/Log4j-config.xsd b/log4j-core-test/src/main/resources/Log4j-config.xsd
index 7539b46ba2..c99ede546b 100644
--- a/log4j-core-test/src/main/resources/Log4j-config.xsd
+++ b/log4j-core-test/src/main/resources/Log4j-config.xsd
@@ -557,16 +557,6 @@
</complexContent>
</complexType>
- <complexType name="JsonLayoutType">
- <complexContent>
- <extension base="tns:AbstractJsonLayoutType">
- <attribute name="propertiesAsList" type="tns:BooleanType" />
- <attribute name="includeTimeMillis" type="tns:BooleanType" />
- <attribute name="objectMessageAsJsonObject" type="tns:BooleanType" />
- </extension>
- </complexContent>
- </complexType>
-
<complexType name="XmlLayoutType">
<complexContent>
<extension base="tns:AbstractJsonLayoutType" />
@@ -633,7 +623,6 @@
<element name="Layout" type="tns:LayoutType" />
<element name="CsvParameterLayout" type="tns:JCsvParameterLayoutType" />
<element name="HtmlLayout" type="tns:HtmlLayoutType" />
- <element name="JsonLayout" type="tns:JsonLayoutType" />
<element name="MessageLayout" type="tns:MessageLayoutType" />
<element name="PatternLayout" type="tns:PatternLayoutType" />
<element name="XmlLayout" type="tns:XmlLayoutType" />
diff --git a/log4j-core-test/src/test/resources/JsonCompleteFileAppenderTest.xml b/log4j-core-test/src/test/resources/JsonCompleteFileAppenderTest.xml
deleted file mode 100644
index 1fac225cba..0000000000
--- a/log4j-core-test/src/test/resources/JsonCompleteFileAppenderTest.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to you under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<Configuration status="OFF">
- <Appenders>
- <File name="JsonFile" fileName="target/JsonCompleteFileAppenderTest.log" immediateFlush="true" append="false">
- <JsonLayout complete="true" charset="UTF-8"/>
- </File>
- </Appenders>
-
- <Loggers>
- <Root level="info" includeLocation="false">
- <AppenderRef ref="JsonFile"/>
- </Root>
- </Loggers>
-</Configuration>
diff --git a/log4j-core-test/src/test/resources/log4j-socket-options.xml b/log4j-core-test/src/test/resources/log4j-socket-options.xml
index 3345c77f7a..45afeb3f62 100644
--- a/log4j-core-test/src/test/resources/log4j-socket-options.xml
+++ b/log4j-core-test/src/test/resources/log4j-socket-options.xml
@@ -18,7 +18,7 @@
<Configuration status="OFF" name="MyApp">
<Appenders>
<Socket name="socket" host="localhost" port="${sys:SocketAppenderSocketOptionsTest.port}" protocol="TCP" ignoreExceptions="false">
- <JsonLayout properties="true"/>
+ <PatternLayout/>
<SocketOptions keepAlive="false" oobInline="false" receiveBufferSize="10000" reuseAddress="false"
rfc1349TrafficClass="IPTOS_LOWCOST" sendBufferSize="8000" soLinger="12345" soTimeout="54321" tcpNoDelay="false">
<SocketPerformancePreferences bandwidth="100" connectionTime="100" latency="100" />
diff --git a/log4j-core-test/src/test/resources/log4j-ssl-socket-options.xml b/log4j-core-test/src/test/resources/log4j-ssl-socket-options.xml
index 9494081ee5..26a3fa8a89 100644
--- a/log4j-core-test/src/test/resources/log4j-ssl-socket-options.xml
+++ b/log4j-core-test/src/test/resources/log4j-ssl-socket-options.xml
@@ -19,7 +19,7 @@
<Appenders>
<Socket name="socket" host="localhost" port="${sys:SecureSocketAppenderSocketOptionsTest.port}" protocol="SSL"
ignoreExceptions="false">
- <JsonLayout properties="true"/>
+ <JsonTemplateLayout/>
<SocketOptions keepAlive="false" receiveBufferSize="10000" reuseAddress="false" rfc1349TrafficClass="IPTOS_LOWCOST"
sendBufferSize="8000" soLinger="12345" soTimeout="54321" tcpNoDelay="false">
<SocketPerformancePreferences bandwidth="100" connectionTime="100" latency="100" />
diff --git a/log4j-core-test/src/test/resources/log4j2-json-layout.xml b/log4j-core-test/src/test/resources/log4j2-json-layout.xml
deleted file mode 100644
index 6fb6b8cf96..0000000000
--- a/log4j-core-test/src/test/resources/log4j2-json-layout.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to you under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<Configuration status="off">
- <Appenders>
- <File name="stdout" ignoreExceptions="false" fileName="target/test-json-layout.log" append="false">
- <JsonLayout compact="true" eventEol="true"/>
- </File>
- </Appenders>
-
- <Loggers>
- <Root level="INFO">
- <AppenderRef ref="stdout"/>
- </Root>
- </Loggers>
-</Configuration>
diff --git a/log4j-core/src/main/resources/Log4j-config.xsd b/log4j-core/src/main/resources/Log4j-config.xsd
index 7539b46ba2..c99ede546b 100644
--- a/log4j-core/src/main/resources/Log4j-config.xsd
+++ b/log4j-core/src/main/resources/Log4j-config.xsd
@@ -557,16 +557,6 @@
</complexContent>
</complexType>
- <complexType name="JsonLayoutType">
- <complexContent>
- <extension base="tns:AbstractJsonLayoutType">
- <attribute name="propertiesAsList" type="tns:BooleanType" />
- <attribute name="includeTimeMillis" type="tns:BooleanType" />
- <attribute name="objectMessageAsJsonObject" type="tns:BooleanType" />
- </extension>
- </complexContent>
- </complexType>
-
<complexType name="XmlLayoutType">
<complexContent>
<extension base="tns:AbstractJsonLayoutType" />
@@ -633,7 +623,6 @@
<element name="Layout" type="tns:LayoutType" />
<element name="CsvParameterLayout" type="tns:JCsvParameterLayoutType" />
<element name="HtmlLayout" type="tns:HtmlLayoutType" />
- <element name="JsonLayout" type="tns:JsonLayoutType" />
<element name="MessageLayout" type="tns:MessageLayoutType" />
<element name="PatternLayout" type="tns:PatternLayoutType" />
<element name="XmlLayout" type="tns:XmlLayoutType" />
diff --git a/log4j-distribution/pom.xml b/log4j-distribution/pom.xml
index 745b8dd6d2..ec471198ee 100644
--- a/log4j-distribution/pom.xml
+++ b/log4j-distribution/pom.xml
@@ -285,18 +285,6 @@
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
- <!-- log4j-layout-jackson-json -->
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson-json</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson-json</artifactId>
- <version>${project.version}</version>
- <classifier>sources</classifier>
- </dependency>
<!-- log4j-layout-jackson-xml -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
diff --git a/log4j-layout-jackson-json/pom.xml b/log4j-layout-jackson-json/pom.xml
deleted file mode 100644
index 2949c363fe..0000000000
--- a/log4j-layout-jackson-json/pom.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to you under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${revision}</version>
- <relativePath>../log4j-parent</relativePath>
- </parent>
-
- <artifactId>log4j-layout-jackson-json</artifactId>
- <name>Apache Log4j Layout for Jackson JSON</name>
- <description>Apache Log4j Layout for Jackson JSON.</description>
- <properties>
- <log4jParentDir>${basedir}/..</log4jParentDir>
- <docLabel>Log4j Layout for Jackson JSON Documentation</docLabel>
- <projectDir>/log4j-layout-json</projectDir>
-
- <!--
- ~ OSGi and JPMS options
- -->
- <bnd-extra-module-options>
- <!-- BND 6.x does not recognize multi-release JARs. Remove when 7.x is published -->
- com.fasterxml.jackson.core;substitute="jackson-core",
- com.fasterxml.jackson.databind;substitute="jackson-databind",
- <!-- The module name of `log4j-layout-jackson` is not recognized in some Maven runs -->
- org.apache.logging.log4j.jackson;substitute="log4j-layout-jackson"
- </bnd-extra-module-options>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson</artifactId>
- <type>test-jar</type>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.lmax</groupId>
- <artifactId>disruptor</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <annotationProcessorPaths combine.children="append">
- <path>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-plugin-processor</artifactId>
- <version>${project.version}</version>
- </path>
- </annotationProcessorPaths>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/JsonSetupContextInitializer.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/JsonSetupContextInitializer.java
deleted file mode 100644
index 44487fcf03..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/JsonSetupContextInitializer.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.databind.Module.SetupContext;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement;
-import org.apache.logging.log4j.core.impl.ThrowableProxy;
-import org.apache.logging.log4j.core.time.Instant;
-import org.apache.logging.log4j.jackson.ExtendedStackTraceElementMixIn;
-import org.apache.logging.log4j.jackson.InstantMixIn;
-import org.apache.logging.log4j.jackson.LevelMixIn;
-import org.apache.logging.log4j.jackson.LogEventJsonMixIn;
-import org.apache.logging.log4j.jackson.MarkerMixIn;
-import org.apache.logging.log4j.jackson.StackTraceElementMixIn;
-import org.apache.logging.log4j.jackson.ThrowableProxyMixIn;
-import org.apache.logging.log4j.jackson.ThrowableProxyWithStacktraceAsStringMixIn;
-import org.apache.logging.log4j.jackson.ThrowableProxyWithoutStacktraceMixIn;
-
-/**
- * Used to set up {@link SetupContext} from different {@link SimpleModule}s.
- * <p>
- * Differs from SetupContextInitializer by installing {@code LogEventJsonMixIn} for LogEvents, not
- * {@code LogEventMixIn}, so it handles {@link ThreadContext} serialization differently.
- * </p>
- * <p>
- * <em>Consider this class private.</em>
- * </p>
- */
-public class JsonSetupContextInitializer {
-
- public void setupModule(
- final SetupContext context, final boolean includeStacktrace, final boolean stacktraceAsString) {
- // JRE classes: we cannot edit those with Jackson annotations
- context.setMixInAnnotations(StackTraceElement.class, StackTraceElementMixIn.class);
- // Log4j API classes: we do not want to edit those with Jackson annotations because the API module should not
- // depend on Jackson.
- context.setMixInAnnotations(Marker.class, MarkerMixIn.class);
- context.setMixInAnnotations(Level.class, LevelMixIn.class);
- context.setMixInAnnotations(Instant.class, InstantMixIn.class);
- context.setMixInAnnotations(LogEvent.class, LogEventJsonMixIn.class); // different ThreadContext handling
- // Log4j Core classes: we do not want to bring in Jackson at runtime if we do not have to.
- context.setMixInAnnotations(ExtendedStackTraceElement.class, ExtendedStackTraceElementMixIn.class);
- context.setMixInAnnotations(
- ThrowableProxy.class,
- includeStacktrace
- ? (stacktraceAsString
- ? ThrowableProxyWithStacktraceAsStringMixIn.class
- : ThrowableProxyMixIn.class)
- : ThrowableProxyWithoutStacktraceMixIn.class);
- }
-}
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/Log4jJsonModule.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/Log4jJsonModule.java
deleted file mode 100644
index f5384bf5ef..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/Log4jJsonModule.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.core.Version;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import org.apache.logging.log4j.jackson.SetupContextInitializer;
-import org.apache.logging.log4j.jackson.SimpleModuleInitializer;
-
-/**
- * <p>
- * <em>Consider this class private.</em>
- * </p>
- */
-class Log4jJsonModule extends SimpleModule {
-
- private static final long serialVersionUID = 1L;
- private final boolean encodeThreadContextAsList;
- private final boolean includeStacktrace;
- private final boolean stacktraceAsString;
-
- Log4jJsonModule(
- final boolean encodeThreadContextAsList,
- final boolean includeStacktrace,
- final boolean stacktraceAsString,
- final boolean objectMessageAsJsonObject) {
- super(Log4jJsonModule.class.getName(), new Version(2, 0, 0, null, null, null));
- this.encodeThreadContextAsList = encodeThreadContextAsList;
- this.includeStacktrace = includeStacktrace;
- this.stacktraceAsString = stacktraceAsString;
- // MUST initialize() here.
- // Calling this from setupModule is too late!
- //noinspection ThisEscapedInObjectConstruction
- new SimpleModuleInitializer().initialize(this, objectMessageAsJsonObject);
- }
-
- @Override
- public void setupModule(final SetupContext context) {
- // Calling super is a MUST!
- super.setupModule(context);
- if (encodeThreadContextAsList) {
- new SetupContextInitializer().setupModule(context, includeStacktrace, stacktraceAsString);
- } else {
- new JsonSetupContextInitializer().setupModule(context, includeStacktrace, stacktraceAsString);
- }
- }
-}
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/Log4jJsonObjectMapper.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/Log4jJsonObjectMapper.java
deleted file mode 100644
index 5ea01a8a8d..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/Log4jJsonObjectMapper.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * A Jackson JSON {@link ObjectMapper} initialized for Log4j.
- * <p>
- * <em>Consider this class private.</em>
- * </p>
- */
-public class Log4jJsonObjectMapper extends ObjectMapper {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Create a new instance using the {@link Log4jJsonModule}.
- */
- public Log4jJsonObjectMapper() {
- this(false, true, false, false);
- }
-
- /**
- * Create a new instance using the {@link Log4jJsonModule}.
- * @param encodeThreadContextAsList true if ThreadContext should be rendered as a list.
- * @param includeStacktrace true if the stack trace should be included.
- * @param stacktraceAsString true if the stack trace should be printed as a simple string.
- * @param objectMessageAsJsonObject true if the ObjectMessage should be converted to a JSON object.
- */
- public Log4jJsonObjectMapper(
- final boolean encodeThreadContextAsList,
- final boolean includeStacktrace,
- final boolean stacktraceAsString,
- final boolean objectMessageAsJsonObject) {
- this.registerModule(new Log4jJsonModule(
- encodeThreadContextAsList, includeStacktrace, stacktraceAsString, objectMessageAsJsonObject));
- this.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
- }
-}
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/JsonJacksonFactory.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/JsonJacksonFactory.java
deleted file mode 100644
index e768ba1817..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/JsonJacksonFactory.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.layout;
-
-import com.fasterxml.jackson.core.PrettyPrinter;
-import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
-import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.logging.log4j.jackson.AbstractJacksonFactory;
-import org.apache.logging.log4j.jackson.JsonConstants;
-import org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper;
-
-class JsonJacksonFactory extends AbstractJacksonFactory {
-
- private final boolean encodeThreadContextAsList;
- private final boolean objectMessageAsJsonObject;
-
- public JsonJacksonFactory(
- final boolean encodeThreadContextAsList,
- final boolean includeStacktrace,
- final boolean stacktraceAsString,
- final boolean objectMessageAsJsonObject) {
- super(includeStacktrace, stacktraceAsString);
- this.encodeThreadContextAsList = encodeThreadContextAsList;
- this.objectMessageAsJsonObject = objectMessageAsJsonObject;
- }
-
- @Override
- protected String getPropertyNameForContextMap() {
- return JsonConstants.ELT_CONTEXT_MAP;
- }
-
- @Override
- protected String getPropertyNameForTimeMillis() {
- return JsonConstants.ELT_TIME_MILLIS;
- }
-
- @Override
- protected String getPropertyNameForInstant() {
- return JsonConstants.ELT_INSTANT;
- }
-
- @Override
- protected String getPropertyNameForNanoTime() {
- return JsonConstants.ELT_NANO_TIME;
- }
-
- @Override
- protected String getPropertyNameForSource() {
- return JsonConstants.ELT_SOURCE;
- }
-
- @Override
- protected String getPropertyNameForStackTrace() {
- return JsonConstants.ELT_EXTENDED_STACK_TRACE;
- }
-
- @Override
- protected PrettyPrinter newCompactPrinter() {
- return new MinimalPrettyPrinter();
- }
-
- @Override
- protected ObjectMapper newObjectMapper() {
- return new Log4jJsonObjectMapper(
- encodeThreadContextAsList, includeStacktrace, stacktraceAsString, objectMessageAsJsonObject);
- }
-
- @Override
- protected PrettyPrinter newPrettyPrinter() {
- return new DefaultPrettyPrinter();
- }
-}
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/JsonLayout.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/JsonLayout.java
deleted file mode 100644
index f4a27b18d5..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/JsonLayout.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.layout;
-
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonUnwrapped;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.core.util.KeyValuePair;
-import org.apache.logging.log4j.jackson.AbstractJacksonLayout;
-import org.apache.logging.log4j.jackson.XmlConstants;
-import org.apache.logging.log4j.plugins.Configurable;
-import org.apache.logging.log4j.plugins.Plugin;
-import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.plugins.PluginElement;
-import org.apache.logging.log4j.plugins.PluginFactory;
-
-/**
- * Note: The JsonLayout should be considered to be deprecated. Please use JsonTemplateLayout instead.
- *
- * Appends a series of JSON events as strings serialized as bytes.
- *
- * <h2>Complete well-formed JSON vs. fragment JSON</h2>
- * <p>
- * If you configure {@code complete="true"}, the appender outputs a well-formed JSON document. By default, with
- * {@code complete="false"}, you should include the output as an <em>external file</em> in a separate file to form a
- * well-formed JSON document.
- * </p>
- * <p>
- * If {@code complete="false"}, the appender does not write the JSON open array character "[" at the start
- * of the document, "]" and the end, nor comma "," between records.
- * </p>
- * <h2>Encoding</h2>
- * <p>
- * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise
- * events containing non ASCII characters could result in corrupted log files.
- * </p>
- * <h2>Pretty vs. compact JSON</h2>
- * <p>
- * By default, the JSON layout is not compact (a.k.a. "pretty") with {@code compact="false"}, which means the
- * appender uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no
- * end-of-line or indentation is used. Message content may contain, of course, escaped end-of-lines.
- * </p>
- * <h2>Additional Fields</h2>
- * <p>
- * This property allows addition of custom fields into generated JSON.
- * {@code <JsonLayout><KeyValuePair key="foo" value="bar"/></JsonLayout>} inserts {@code "foo":"bar"} directly
- * into JSON output. Supports Lookup expressions.
- * </p>
- */
-@Configurable(elementType = Layout.ELEMENT_TYPE, printObject = true)
-@Plugin
-public final class JsonLayout extends AbstractJacksonLayout {
-
- public static class Builder<B extends Builder<B>> extends AbstractJacksonLayout.Builder<B>
- implements org.apache.logging.log4j.plugins.util.Builder<JsonLayout> {
-
- @PluginBuilderAttribute
- private boolean propertiesAsList;
-
- @PluginBuilderAttribute
- private boolean objectMessageAsJsonObject;
-
- @PluginElement("AdditionalField")
- private KeyValuePair[] additionalFields;
-
- public Builder() {
- super();
- setCharset(StandardCharsets.UTF_8);
- }
-
- @Override
- public JsonLayout build() {
- final boolean encodeThreadContextAsList = isProperties() && propertiesAsList;
- final String headerPattern = toStringOrNull(getHeader());
- final String footerPattern = toStringOrNull(getFooter());
- return new JsonLayout(
- getConfiguration(),
- isLocationInfo(),
- isProperties(),
- encodeThreadContextAsList,
- isComplete(),
- isCompact(),
- getEventEol(),
- getEndOfLine(),
- headerPattern,
- footerPattern,
- getCharset(),
- isIncludeStacktrace(),
- isStacktraceAsString(),
- isIncludeNullDelimiter(),
- isIncludeTimeMillis(),
- getAdditionalFields(),
- getObjectMessageAsJsonObject());
- }
-
- @Override
- public KeyValuePair[] getAdditionalFields() {
- return additionalFields;
- }
-
- public boolean getObjectMessageAsJsonObject() {
- return objectMessageAsJsonObject;
- }
-
- public boolean isPropertiesAsList() {
- return propertiesAsList;
- }
-
- @Override
- public B setAdditionalFields(final KeyValuePair[] additionalFields) {
- this.additionalFields = additionalFields;
- return asBuilder();
- }
-
- public B setObjectMessageAsJsonObject(final boolean objectMessageAsJsonObject) {
- this.objectMessageAsJsonObject = objectMessageAsJsonObject;
- return asBuilder();
- }
-
- public B setPropertiesAsList(final boolean propertiesAsList) {
- this.propertiesAsList = propertiesAsList;
- return asBuilder();
- }
- }
-
- @JsonRootName(XmlConstants.ELT_EVENT)
- public static class JsonLogEventWithAdditionalFields extends LogEventWithAdditionalFields {
-
- public JsonLogEventWithAdditionalFields(final LogEvent logEvent, final Map<String, String> additionalFields) {
- super(logEvent, additionalFields);
- }
-
- @Override
- @JsonAnyGetter
- public Map<String, String> getAdditionalFields() {
- return super.getAdditionalFields();
- }
-
- @Override
- @JsonUnwrapped
- @JsonSerialize(as = LogEvent.class)
- public LogEvent getLogEvent() {
- return super.getLogEvent();
- }
- }
-
- private static final String DEFAULT_FOOTER = "]";
-
- private static final String DEFAULT_HEADER = "[";
-
- static final String CONTENT_TYPE = "application/json";
-
- /**
- * Creates a JSON Layout using the default settings. Useful for testing.
- *
- * @return A JSON Layout.
- */
- public static JsonLayout createDefaultLayout() {
- return new JsonLayout(
- new DefaultConfiguration(),
- false,
- false,
- false,
- false,
- false,
- false,
- null,
- DEFAULT_HEADER,
- DEFAULT_FOOTER,
- StandardCharsets.UTF_8,
- true,
- false,
- false,
- false,
- null,
- false);
- }
-
- @PluginFactory
- public static <B extends Builder<B>> B newBuilder() {
- return new Builder<B>().asBuilder();
- }
-
- private JsonLayout(
- final Configuration config,
- final boolean locationInfo,
- final boolean properties,
- final boolean encodeThreadContextAsList,
- final boolean complete,
- final boolean compact,
- final boolean eventEol,
- final String endOfLine,
- final String headerPattern,
- final String footerPattern,
- final Charset charset,
- final boolean includeStacktrace,
- final boolean stacktraceAsString,
- final boolean includeNullDelimiter,
- final boolean includeTimeMillis,
- final KeyValuePair[] additionalFields,
- final boolean objectMessageAsJsonObject) {
- super(
- config,
- new JsonJacksonFactory(
- encodeThreadContextAsList,
- includeStacktrace,
- stacktraceAsString,
- objectMessageAsJsonObject)
- .newWriter(locationInfo, properties, compact, includeTimeMillis),
- charset,
- compact,
- complete,
- eventEol,
- endOfLine,
- PatternLayout.newSerializerBuilder()
- .setConfiguration(config)
- .setPattern(headerPattern)
- .setDefaultPattern(DEFAULT_HEADER)
- .build(),
- PatternLayout.newSerializerBuilder()
- .setConfiguration(config)
- .setPattern(footerPattern)
- .setDefaultPattern(DEFAULT_FOOTER)
- .build(),
- includeNullDelimiter,
- additionalFields);
- }
-
- @Override
- protected LogEventWithAdditionalFields createLogEventWithAdditionalFields(
- final LogEvent event, final Map<String, String> additionalFieldsMap) {
- return new JsonLogEventWithAdditionalFields(event, additionalFieldsMap);
- }
-
- @Override
- public Map<String, String> getContentFormat() {
- final Map<String, String> result = new HashMap<>();
- result.put("version", "2.0");
- return result;
- }
-
- /**
- * @return The content type.
- */
- @Override
- public String getContentType() {
- return CONTENT_TYPE + "; charset=" + this.getCharset();
- }
-
- /**
- * Returns appropriate JSON footer.
- *
- * @return a byte array containing the footer, closing the JSON array.
- */
- @Override
- public byte[] getFooter() {
- if (!this.complete) {
- return null;
- }
- final StringBuilder buf = new StringBuilder();
- buf.append(this.eol);
- final String str = serializeToString(getFooterSerializer());
- if (str != null) {
- buf.append(str);
- }
- buf.append(this.eol);
- return getBytes(buf.toString());
- }
-
- /**
- * Returns appropriate JSON header.
- *
- * @return a byte array containing the header, opening the JSON array.
- */
- @Override
- public byte[] getHeader() {
- if (!this.complete) {
- return null;
- }
- final StringBuilder buf = new StringBuilder();
- final String str = serializeToString(getHeaderSerializer());
- if (str != null) {
- buf.append(str);
- }
- buf.append(this.eol);
- return getBytes(buf.toString());
- }
-
- @Override
- public void toSerializable(final LogEvent event, final Writer writer) throws IOException {
- if (complete && eventCount > 0) {
- writer.append(", ");
- }
- super.toSerializable(event, writer);
- }
-}
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/package-info.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/package-info.java
deleted file mode 100644
index 1c7a570c92..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/layout/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-@Export
-@Version("1.0.0")
-package org.apache.logging.log4j.jackson.json.layout;
-
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/package-info.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/package-info.java
deleted file mode 100644
index cfda652628..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-@Export
-@Version("1.0.0")
-package org.apache.logging.log4j.jackson.json;
-
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/parser/JsonLogEventParser.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/parser/JsonLogEventParser.java
deleted file mode 100644
index 289c1541b7..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/parser/JsonLogEventParser.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.parser;
-
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.parser.AbstractJacksonLogEventParser;
-import org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper;
-
-/**
- * Parses the output from XmlLayout layout into instances of {@link LogEvent}.
- */
-public class JsonLogEventParser extends AbstractJacksonLogEventParser {
-
- public JsonLogEventParser() {
- super(new Log4jJsonObjectMapper());
- }
-}
diff --git a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/parser/package-info.java b/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/parser/package-info.java
deleted file mode 100644
index 5c19676922..0000000000
--- a/log4j-layout-jackson-json/src/main/java/org/apache/logging/log4j/jackson/json/parser/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-@Export
-@Version("1.0.0")
-package org.apache.logging.log4j.jackson.json.parser;
-
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/JacksonIssue429MyNamesTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/JacksonIssue429MyNamesTest.java
deleted file mode 100644
index ec2b063a30..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/JacksonIssue429MyNamesTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.JsonToken;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import java.io.IOException;
-import org.apache.logging.log4j.core.test.categories.Layouts;
-import org.apache.logging.log4j.util.Strings;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(Layouts.Json.class)
-public class JacksonIssue429MyNamesTest {
-
- @SuppressWarnings("serial")
- static class MyStackTraceElementDeserializer extends StdScalarDeserializer<StackTraceElement> {
- private static final long serialVersionUID = 1L;
-
- public static final MyStackTraceElementDeserializer instance = new MyStackTraceElementDeserializer();
-
- public MyStackTraceElementDeserializer() {
- super(StackTraceElement.class);
- }
-
- @Override
- public StackTraceElement deserialize(final JsonParser jp, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
- JsonToken t = jp.getCurrentToken();
- // Must get an Object
- if (t == JsonToken.START_OBJECT) {
- String className = Strings.EMPTY, methodName = Strings.EMPTY, fileName = Strings.EMPTY;
- int lineNumber = -1;
-
- while ((t = jp.nextValue()) != JsonToken.END_OBJECT) {
- final String propName = jp.getCurrentName();
- if ("class".equals(propName)) {
- className = jp.getText();
- } else if ("file".equals(propName)) {
- fileName = jp.getText();
- } else if ("line".equals(propName)) {
- if (t.isNumeric()) {
- lineNumber = jp.getIntValue();
- } else {
- throw JsonMappingException.from(
- jp, "Non-numeric token (" + t + ") for property 'lineNumber'");
- }
- } else if ("method".equals(propName)) {
- methodName = jp.getText();
- } else if ("nativeMethod".equals(propName)) {
- // no setter, not passed via constructor: ignore
- } else {
- handleUnknownProperty(jp, ctxt, _valueClass, propName);
- }
- }
- return new StackTraceElement(className, methodName, fileName, lineNumber);
- }
- throw ctxt.mappingException(_valueClass, t);
- }
- }
-
- static class StackTraceBean {
- public static final int NUM = 13;
-
- @JsonProperty("Location")
- @JsonDeserialize(using = MyStackTraceElementDeserializer.class)
- private StackTraceElement location;
- }
-
- private static final ObjectMapper SHARED_MAPPER = new ObjectMapper();
-
- private final ObjectMapper MAPPER = objectMapper();
-
- protected String aposToQuotes(final String json) {
- return json.replace("'", "\"");
- }
-
- protected ObjectMapper objectMapper() {
- return SHARED_MAPPER;
- }
-
- @Test
- public void testStackTraceElementWithCustom() throws Exception {
- // first, via bean that contains StackTraceElement
- final StackTraceBean bean = MAPPER.readValue(
- aposToQuotes(
- "{'Location':{'class':'package.SomeClass','method':'someMethod','file':'SomeClass.java','line':13}}"),
- StackTraceBean.class);
- Assert.assertNotNull(bean);
- Assert.assertNotNull(bean.location);
- Assert.assertEquals(StackTraceBean.NUM, bean.location.getLineNumber());
-
- // and then directly, iff registered
- final ObjectMapper mapper = new ObjectMapper();
- final SimpleModule module = new SimpleModule();
- module.addDeserializer(StackTraceElement.class, new MyStackTraceElementDeserializer());
- mapper.registerModule(module);
-
- final StackTraceElement elem = mapper.readValue(
- aposToQuotes("{'class':'package.SomeClass','method':'someMethod','file':'SomeClass.java','line':13}"),
- StackTraceElement.class);
- Assert.assertNotNull(elem);
- Assert.assertEquals(StackTraceBean.NUM, elem.getLineNumber());
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/JacksonIssue429Test.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/JacksonIssue429Test.java
deleted file mode 100644
index 3afb6468d4..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/JacksonIssue429Test.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import java.io.IOException;
-import org.apache.logging.log4j.core.test.categories.Layouts;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(Layouts.Json.class)
-public class JacksonIssue429Test {
-
- @SuppressWarnings("serial")
- static class Jackson429StackTraceElementDeserializer extends StdDeserializer<StackTraceElement> {
- private static final long serialVersionUID = 1L;
-
- public Jackson429StackTraceElementDeserializer() {
- super(StackTraceElement.class);
- }
-
- @Override
- public StackTraceElement deserialize(final JsonParser jp, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
- jp.skipChildren();
- return new StackTraceElement("a", "b", "b", StackTraceBean.NUM);
- }
- }
-
- static class StackTraceBean {
- public static final int NUM = 13;
-
- @JsonProperty("Location")
- @JsonDeserialize(using = Jackson429StackTraceElementDeserializer.class)
- private StackTraceElement location;
- }
-
- private static final ObjectMapper SHARED_MAPPER = new ObjectMapper();
-
- private final ObjectMapper MAPPER = objectMapper();
-
- protected String aposToQuotes(final String json) {
- return json.replace("'", "\"");
- }
-
- protected ObjectMapper objectMapper() {
- return SHARED_MAPPER;
- }
-
- @Test
- public void testStackTraceElementWithCustom() throws Exception {
- // first, via bean that contains StackTraceElement
- final StackTraceBean bean = MAPPER.readValue(aposToQuotes("{'Location':'foobar'}"), StackTraceBean.class);
- Assert.assertNotNull(bean);
- Assert.assertNotNull(bean.location);
- Assert.assertEquals(StackTraceBean.NUM, bean.location.getLineNumber());
-
- // and then directly, iff registered
- final ObjectMapper mapper = new ObjectMapper();
- final SimpleModule module = new SimpleModule();
- module.addDeserializer(StackTraceElement.class, new Jackson429StackTraceElementDeserializer());
- mapper.registerModule(module);
-
- final StackTraceElement elem = mapper.readValue(
- aposToQuotes("{'class':'package.SomeClass','method':'someMethod','file':'SomeClass.java','line':123}"),
- StackTraceElement.class);
- Assert.assertNotNull(elem);
- Assert.assertEquals(StackTraceBean.NUM, elem.getLineNumber());
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/LevelMixInJsonTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/LevelMixInJsonTest.java
deleted file mode 100644
index 80ef760444..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/LevelMixInJsonTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.logging.log4j.jackson.LevelMixInTest;
-
-public class LevelMixInJsonTest extends LevelMixInTest {
-
- @Override
- protected ObjectMapper newObjectMapper() {
- return new Log4jJsonObjectMapper(false, true, false, false);
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/MarkerMixInJsonTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/MarkerMixInJsonTest.java
deleted file mode 100644
index 86d4cc45f1..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/MarkerMixInJsonTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.logging.log4j.jackson.AbstractMarkerMixInTest;
-
-public class MarkerMixInJsonTest extends AbstractMarkerMixInTest {
-
- @Override
- protected ObjectMapper newObjectMapper() {
- return new Log4jJsonObjectMapper();
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/StackTraceElementJsonMixInTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/StackTraceElementJsonMixInTest.java
deleted file mode 100644
index c307819aea..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/StackTraceElementJsonMixInTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import java.io.IOException;
-import org.apache.logging.log4j.core.test.categories.Layouts;
-import org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(Layouts.Json.class)
-public class StackTraceElementJsonMixInTest {
-
- protected String aposToQuotes(final String json) {
- return json.replace("'", "\"");
- }
-
- /**
- * @param mapper
- * @throws JsonProcessingException
- * @throws IOException
- * @throws JsonParseException
- * @throws JsonMappingException
- */
- private void roundtrip(final ObjectMapper mapper)
- throws JsonProcessingException, IOException, JsonParseException, JsonMappingException {
- final StackTraceElement expected =
- new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
- final String s = mapper.writeValueAsString(expected);
- final StackTraceElement actual = mapper.readValue(s, StackTraceElement.class);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testFromJsonWithLog4jModule() throws Exception {
- final ObjectMapper mapper = new ObjectMapper();
- final boolean encodeThreadContextAsList = false;
- final SimpleModule module = new Log4jJsonModule(encodeThreadContextAsList, true, false, false);
- module.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
- mapper.registerModule(module);
- final StackTraceElement expected =
- new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
- final String s = this.aposToQuotes(
- "{'class':'package.SomeClass','method':'someMethod','file':'SomeClass.java','line':123}");
- final StackTraceElement actual = mapper.readValue(s, StackTraceElement.class);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testFromJsonWithSimpleModule() throws Exception {
- final ObjectMapper mapper = new ObjectMapper();
- final SimpleModule module = new SimpleModule();
- module.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
- mapper.registerModule(module);
- final StackTraceElement expected =
- new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
- final String s = this.aposToQuotes(
- "{'class':'package.SomeClass','method':'someMethod','file':'SomeClass.java','line':123}");
- final StackTraceElement actual = mapper.readValue(s, StackTraceElement.class);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testLog4jJsonObjectMapper() throws Exception {
- this.roundtrip(new Log4jJsonObjectMapper());
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/ConcurrentLoggingWithJsonLayoutTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/ConcurrentLoggingWithJsonLayoutTest.java
deleted file mode 100644
index 2c3164a703..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/ConcurrentLoggingWithJsonLayoutTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.layout;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
-
-import java.io.File;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.junit.AfterClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-/**
- * Test for LOG4J2-1769.
- *
- * @since 2.8
- */
-public class ConcurrentLoggingWithJsonLayoutTest {
-
- private class LoggingThread extends Thread {
- private final Set<Thread> threads;
- private final Logger log;
-
- LoggingThread(final Set<Thread> threads, final Logger log) {
- this.threads = threads;
- this.log = log;
- }
-
- @Override
- public void run() {
- log.info(threads.size());
- try {
- for (int i = 0; i < 64; i++) {
- log.info("First message.");
- log.info("Second message.");
- }
- } finally {
- threads.remove(this);
- }
- }
- }
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule("log4j2-json-layout.xml");
-
- private static final String PATH = "target/test-json-layout.log";
-
- @AfterClass
- public static void after() {
- new File(PATH).delete();
- }
-
- @Test
- public void testConcurrentLogging() throws Throwable {
- final Logger log = context.getLogger(ConcurrentLoggingWithJsonLayoutTest.class);
- final Set<Thread> threads = Collections.synchronizedSet(new HashSet<Thread>());
- final List<Throwable> thrown = Collections.synchronizedList(new ArrayList<Throwable>());
-
- for (int x = 0; x < Runtime.getRuntime().availableProcessors() * 2; x++) {
- final Thread t = new LoggingThread(threads, log);
- threads.add(t);
-
- // Appender is configured with ignoreExceptions="false";
- // any exceptions are propagated to the caller, so we can catch them here.
- t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
- @Override
- public void uncaughtException(final Thread t, final Throwable e) {
- thrown.add(e);
- }
- });
- t.start();
- }
-
- while (!threads.isEmpty()) {
- log.info("not done going to sleep...");
- Thread.sleep(10);
- }
-
- // if any error occurred, fail this test
- assertThat(thrown, equalTo(Collections.emptyList()));
-
- // simple test to ensure content is not corrupted
- final List<String> lines = Files.readAllLines(new File(PATH).toPath(), Charset.defaultCharset());
- for (final String line : lines) {
- assertThat(line, startsWith("{\"instant\":{\"epochSecond\":"));
- assertThat(line, containsString("\"threadPriority\":5"));
- }
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/JsonLayoutMillisTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/JsonLayoutMillisTest.java
deleted file mode 100644
index 17ad498bb4..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/JsonLayoutMillisTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.layout;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.test.appender.ListAppender;
-import org.apache.logging.log4j.core.test.categories.Layouts;
-import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-/**
- * Tests the JsonLayout class with millis.
- */
-@Category(Layouts.Json.class)
-public class JsonLayoutMillisTest {
-
- private static final String CONFIG = "log4j2-json-layout-timestamp.xml";
-
- private ListAppender app;
-
- @Rule
- public LoggerContextRule context = new LoggerContextRule(CONFIG);
-
- private Logger logger;
-
- private void assertEventCount(final List<LogEvent> events, final int expected) {
- assertEquals("Incorrect number of events.", expected, events.size());
- }
-
- @Before
- public void before() {
- logger = context.getLogger("LayoutTest");
- //
- app = context.getListAppender("List").clear();
- }
-
- @Test
- public void testTimestamp() {
- logger.info("This is a test message");
- final List<String> message = app.getMessages();
- assertTrue("No messages", message != null && message.size() > 0);
- final String json = message.get(0);
- System.out.println(json);
- assertNotNull("No JSON message", json);
- assertTrue("No timestamp", json.contains("\"timeMillis\":"));
- assertFalse("Instant is present", json.contains("instant:"));
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/JsonLayoutTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/JsonLayoutTest.java
deleted file mode 100644
index 0a8c1e521e..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/JsonLayoutTest.java
+++ /dev/null
@@ -1,694 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.layout;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.async.RingBufferLogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.impl.ContextDataFactory;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.impl.MutableLogEvent;
-import org.apache.logging.log4j.core.lookup.JavaLookup;
-import org.apache.logging.log4j.core.test.BasicConfigurationFactory;
-import org.apache.logging.log4j.core.test.appender.ListAppender;
-import org.apache.logging.log4j.core.test.junit.ConfigurationFactoryType;
-import org.apache.logging.log4j.core.test.layout.LogEventFixtures;
-import org.apache.logging.log4j.core.time.internal.DummyNanoClock;
-import org.apache.logging.log4j.core.time.internal.SystemClock;
-import org.apache.logging.log4j.core.util.KeyValuePair;
-import org.apache.logging.log4j.jackson.AbstractJacksonLayout;
-import org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper;
-import org.apache.logging.log4j.message.*;
-import org.apache.logging.log4j.spi.AbstractLogger;
-import org.apache.logging.log4j.test.junit.UsingAnyThreadContext;
-import org.apache.logging.log4j.util.SortedArrayStringMap;
-import org.apache.logging.log4j.util.StringMap;
-import org.apache.logging.log4j.util.Strings;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests the JsonLayout class.
- */
-@UsingAnyThreadContext
-@ConfigurationFactoryType(BasicConfigurationFactory.class)
-public class JsonLayoutTest {
- private static class TestClass {
- private int value;
-
- public int getValue() {
- return value;
- }
-
- public void setValue(final int value) {
- this.value = value;
- }
- }
-
- private static final String DQUOTE = "\"";
-
- LoggerContext ctx = LoggerContext.getContext();
-
- Logger rootLogger = this.ctx.getRootLogger();
-
- private void checkAt(final String expected, final int lineIndex, final List<String> list) {
- final String trimedLine = list.get(lineIndex).trim();
- assertEquals(trimedLine, expected, "Incorrect line index " + lineIndex + ": " + Strings.dquote(trimedLine));
- }
-
- private void checkContains(final String expected, final List<String> list) {
- for (final String string : list) {
- final String trimedLine = string.trim();
- if (trimedLine.equals(expected)) {
- return;
- }
- }
- fail("Cannot find " + expected + " in " + list);
- }
-
- private void checkMapEntry(
- final String key,
- final String value,
- final boolean compact,
- final String str,
- final boolean contextMapAslist) {
- this.toPropertySeparator(compact);
- if (contextMapAslist) {
- // {"key":"KEY", "value":"VALUE"}
- final String expected = String.format("{\"key\":\"%s\",\"value\":\"%s\"}", key, value);
- assertTrue(str.contains(expected), "Cannot find contextMapAslist " + expected + " in " + str);
- } else {
- // "KEY":"VALUE"
- final String expected = String.format("\"%s\":\"%s\"", key, value);
- assertTrue(str.contains(expected), "Cannot find contextMap " + expected + " in " + str);
- }
- }
-
- private void checkProperty(final String key, final String value, final boolean compact, final String str) {
- final String propSep = this.toPropertySeparator(compact);
- // {"key":"MDC.B","value":"B_Value"}
- final String expected = String.format("\"%s\"%s\"%s\"", key, propSep, value);
- assertTrue(str.contains(expected), "Cannot find " + expected + " in " + str);
- }
-
- private void checkPropertyName(final String name, final boolean compact, final String str) {
- final String propSep = this.toPropertySeparator(compact);
- assertTrue(str.contains(DQUOTE + name + DQUOTE + propSep), str);
- }
-
- private void checkPropertyNameAbsent(final String name, final boolean compact, final String str) {
- final String propSep = this.toPropertySeparator(compact);
- assertFalse(str.contains(DQUOTE + name + DQUOTE + propSep), str);
- }
-
- private String prepareJsonForObjectMessageAsJsonObjectTests(
- final int value, final boolean objectMessageAsJsonObject) {
- final TestClass testClass = new TestClass();
- testClass.setValue(value);
- // @formatter:off
- final Log4jLogEvent expected = Log4jLogEvent.newBuilder()
- .setLoggerName("a.B")
- .setLoggerFqcn("f.q.c.n")
- .setLevel(Level.DEBUG)
- .setMessage(new ObjectMessage(testClass))
- .setThreadName("threadName")
- .setTimeMillis(1)
- .build();
- // @formatter:off
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setCompact(true)
- .setObjectMessageAsJsonObject(objectMessageAsJsonObject)
- .build();
- // @formatter:off
- return layout.toSerializable(expected);
- }
-
- private String prepareJsonForStacktraceTests(final boolean stacktraceAsString) {
- final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
- // @formatter:off
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setCompact(true)
- .setIncludeStacktrace(true)
- .setStacktraceAsString(stacktraceAsString)
- .build();
- // @formatter:off
- return layout.toSerializable(expected);
- }
-
- @Test
- public void testAdditionalFields() {
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(false)
- .setProperties(false)
- .setComplete(false)
- .setCompact(true)
- .setEventEol(false)
- .setIncludeStacktrace(false)
- .setAdditionalFields(new KeyValuePair[] {
- new KeyValuePair("KEY1", "VALUE1"), new KeyValuePair("KEY2", "${java:runtime}"),
- })
- .setCharset(StandardCharsets.UTF_8)
- .setConfiguration(ctx.getConfiguration())
- .build();
- final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
- assertTrue(str.contains("\"KEY1\":\"VALUE1\""), str);
- assertTrue(str.contains("\"KEY2\":\"" + new JavaLookup().getRuntime() + "\""), str);
- }
-
- @Test
- public void testMutableLogEvent() {
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(false)
- .setProperties(false)
- .setComplete(false)
- .setCompact(true)
- .setEventEol(false)
- .setIncludeStacktrace(false)
- .setAdditionalFields(new KeyValuePair[] {
- new KeyValuePair("KEY1", "VALUE1"), new KeyValuePair("KEY2", "${java:runtime}"),
- })
- .setCharset(StandardCharsets.UTF_8)
- .setConfiguration(ctx.getConfiguration())
- .build();
- final Log4jLogEvent logEvent = LogEventFixtures.createLogEvent();
- final MutableLogEvent mutableEvent = new MutableLogEvent();
- mutableEvent.initFrom(logEvent);
- final String strLogEvent = layout.toSerializable(logEvent);
- final String strMutableEvent = layout.toSerializable(mutableEvent);
- assertEquals(strLogEvent, strMutableEvent, strMutableEvent);
- }
-
- private void testAllFeatures(
- final boolean locationInfo,
- final boolean compact,
- final boolean eventEol,
- final String endOfLine,
- final boolean includeContext,
- final boolean contextMapAslist,
- final boolean includeStacktrace)
- throws Exception {
- final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
- // @formatter:off
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(locationInfo)
- .setProperties(includeContext)
- .setPropertiesAsList(contextMapAslist)
- .setComplete(false)
- .setCompact(compact)
- .setEventEol(eventEol)
- .setEndOfLine(endOfLine)
- .setCharset(StandardCharsets.UTF_8)
- .setIncludeStacktrace(includeStacktrace)
- .build();
- // @formatter:off
- final String str = layout.toSerializable(expected);
- this.toPropertySeparator(compact);
- if (endOfLine == null) {
- // Just check for \n since \r might or might not be there.
- assertEquals(!compact || eventEol, str.contains("\n"), str);
- } else {
- assertEquals(!compact || eventEol, str.contains(endOfLine), str);
- assertEquals(compact && eventEol, str.endsWith(endOfLine), str);
- }
- assertEquals(locationInfo, str.contains("source"), str);
- assertEquals(includeContext, str.contains("contextMap"), str);
- final Log4jLogEvent actual = new Log4jJsonObjectMapper(contextMapAslist, includeStacktrace, false, false)
- .readValue(str, Log4jLogEvent.class);
- LogEventFixtures.assertEqualLogEvents(expected, actual, locationInfo, includeContext, includeStacktrace);
- if (includeContext) {
- this.checkMapEntry("MDC.A", "A_Value", compact, str, contextMapAslist);
- this.checkMapEntry("MDC.B", "B_Value", compact, str, contextMapAslist);
- }
- //
- assertNull(actual.getThrown());
- // make sure the names we want are used
- this.checkPropertyName("instant", compact, str);
- this.checkPropertyName("thread", compact, str); // and not threadName
- this.checkPropertyName("level", compact, str);
- this.checkPropertyName("loggerName", compact, str);
- this.checkPropertyName("marker", compact, str);
- this.checkPropertyName("name", compact, str);
- this.checkPropertyName("parents", compact, str);
- this.checkPropertyName("message", compact, str);
- this.checkPropertyName("thrown", compact, str);
- this.checkPropertyName("cause", compact, str);
- this.checkPropertyName("commonElementCount", compact, str);
- this.checkPropertyName("localizedMessage", compact, str);
- if (includeStacktrace) {
- this.checkPropertyName("extendedStackTrace", compact, str);
- this.checkPropertyName("class", compact, str);
- this.checkPropertyName("method", compact, str);
- this.checkPropertyName("file", compact, str);
- this.checkPropertyName("line", compact, str);
- this.checkPropertyName("exact", compact, str);
- this.checkPropertyName("location", compact, str);
- this.checkPropertyName("version", compact, str);
- } else {
- this.checkPropertyNameAbsent("extendedStackTrace", compact, str);
- }
- this.checkPropertyName("suppressed", compact, str);
- this.checkPropertyName("loggerFqcn", compact, str);
- this.checkPropertyName("endOfBatch", compact, str);
- if (includeContext) {
- this.checkPropertyName("contextMap", compact, str);
- } else {
- this.checkPropertyNameAbsent("contextMap", compact, str);
- }
- this.checkPropertyName("contextStack", compact, str);
- if (locationInfo) {
- this.checkPropertyName("source", compact, str);
- } else {
- this.checkPropertyNameAbsent("source", compact, str);
- }
- // check some attrs
- this.checkProperty("loggerFqcn", "f.q.c.n", compact, str);
- this.checkProperty("loggerName", "a.B", compact, str);
- }
-
- @Test
- public void testContentType() {
- final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
- assertEquals("application/json; charset=UTF-8", layout.getContentType());
- }
-
- @Test
- public void testDefaultCharset() {
- final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
- assertEquals(StandardCharsets.UTF_8, layout.getCharset());
- }
-
- @Test
- public void testEscapeLayout() throws Exception {
- final Map<String, Appender> appenders = this.rootLogger.getAppenders();
- for (final Appender appender : appenders.values()) {
- this.rootLogger.removeAppender(appender);
- }
- final Configuration configuration = rootLogger.getContext().getConfiguration();
- // set up appender
- final boolean propertiesAsList = false;
- // @formatter:off
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(configuration)
- .setLocationInfo(true)
- .setProperties(true)
- .setPropertiesAsList(propertiesAsList)
- .setComplete(true)
- .setCompact(false)
- .setEventEol(false)
- .setIncludeStacktrace(true)
- .build();
- // @formatter:on
- final ListAppender appender = new ListAppender("List", null, layout, true, false);
- appender.start();
-
- // set appender on root and set level to debug
- this.rootLogger.addAppender(appender);
- this.rootLogger.setLevel(Level.DEBUG);
-
- // output starting message
- this.rootLogger.debug("Here is a quote ' and then a double quote \"");
-
- appender.stop();
-
- final List<String> list = appender.getMessages();
-
- this.checkAt("[", 0, list);
- this.checkAt("{", 1, list);
- this.checkContains("\"level\" : \"DEBUG\",", list);
- this.checkContains("\"message\" : \"Here is a quote ' and then a double quote \\\"\",", list);
- this.checkContains("\"loggerFqcn\" : \"" + AbstractLogger.class.getName() + "\",", list);
- for (final Appender app : appenders.values()) {
- this.rootLogger.addAppender(app);
- }
- }
-
- @Test
- public void testExcludeStacktrace() throws Exception {
- this.testAllFeatures(false, false, false, null, false, false, false);
- }
-
- @Test
- public void testLocationOnCustomEndOfLine() throws Exception {
- this.testAllFeatures(true, true, true, "CUSTOM_END_OF_LINE", true, false, true);
- }
-
- @Test
- public void testIncludeNullDelimiterFalse() {
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setCompact(true)
- .setIncludeNullDelimiter(false)
- .build();
- final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
- assertFalse(str.endsWith("\0"));
- }
-
- @Test
- public void testIncludeNullDelimiterTrue() {
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setCompact(true)
- .setIncludeNullDelimiter(true)
- .build();
- final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
- assertTrue(str.endsWith("\0"));
- }
-
- /**
- * Test case for MDC conversion pattern.
- */
- @Test
- public void testLayout() {
- final Map<String, Appender> appenders = this.rootLogger.getAppenders();
- for (final Appender appender : appenders.values()) {
- this.rootLogger.removeAppender(appender);
- }
- final Configuration configuration = rootLogger.getContext().getConfiguration();
- // set up appender
- // Use [[ and ]] to test header and footer (instead of [ and ])
- final boolean propertiesAsList = false;
- // @formatter:off
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(configuration)
- .setLocationInfo(true)
- .setProperties(true)
- .setPropertiesAsList(propertiesAsList)
- .setComplete(true)
- .setCompact(false)
- .setEventEol(false)
- .setHeader("[[".getBytes(Charset.defaultCharset()))
- .setFooter("]]".getBytes(Charset.defaultCharset()))
- .setIncludeStacktrace(true)
- .build();
- // @formatter:on
- final ListAppender appender = new ListAppender("List", null, layout, true, false);
- appender.start();
-
- // set appender on root and set level to debug
- this.rootLogger.addAppender(appender);
- this.rootLogger.setLevel(Level.DEBUG);
-
- // output starting message
- this.rootLogger.debug("starting mdc pattern test");
-
- this.rootLogger.debug("empty mdc");
-
- ThreadContext.put("key1", "value1");
- ThreadContext.put("key2", "value2");
-
- this.rootLogger.debug("filled mdc");
-
- ThreadContext.remove("key1");
- ThreadContext.remove("key2");
-
- this.rootLogger.error("finished mdc pattern test", new NullPointerException("test"));
-
- appender.stop();
-
- final List<String> list = appender.getMessages();
-
- this.checkAt("[[", 0, list);
- this.checkAt("{", 1, list);
- this.checkContains("\"loggerFqcn\" : \"" + AbstractLogger.class.getName() + "\",", list);
- this.checkContains("\"level\" : \"DEBUG\",", list);
- this.checkContains("\"message\" : \"starting mdc pattern test\",", list);
- for (final Appender app : appenders.values()) {
- this.rootLogger.addAppender(app);
- }
- }
-
- @Test
- public void testLayoutLoggerName() throws Exception {
- final boolean propertiesAsList = false;
- // @formatter:off
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(false)
- .setProperties(false)
- .setPropertiesAsList(propertiesAsList)
- .setComplete(false)
- .setCompact(true)
- .setEventEol(false)
- .setCharset(StandardCharsets.UTF_8)
- .setIncludeStacktrace(true)
- .build();
- // @formatter:on
- // @formatter:off
- final Log4jLogEvent expected = Log4jLogEvent.newBuilder()
- .setLoggerName("a.B")
- .setLoggerFqcn("f.q.c.n")
- .setLevel(Level.DEBUG)
- .setMessage(new SimpleMessage("M"))
- .setThreadName("threadName")
- .setTimeMillis(1)
- .build();
- // @formatter:on
- final String str = layout.toSerializable(expected);
- assertTrue(str.contains("\"loggerName\":\"a.B\""), str);
- final Log4jLogEvent actual =
- new Log4jJsonObjectMapper(propertiesAsList, true, false, false).readValue(str, Log4jLogEvent.class);
- assertEquals(expected.getLoggerName(), actual.getLoggerName());
- assertEquals(expected, actual);
- }
-
- @Test
- public void testLayoutMessageWithCurlyBraces() throws Exception {
- final boolean propertiesAsList = false;
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(false)
- .setProperties(false)
- .setPropertiesAsList(propertiesAsList)
- .setComplete(false)
- .setCompact(true)
- .setEventEol(false)
- .setCharset(StandardCharsets.UTF_8)
- .setIncludeStacktrace(true)
- .build();
- final Log4jLogEvent expected = Log4jLogEvent.newBuilder()
- .setLoggerName("a.B")
- .setLoggerFqcn("f.q.c.n")
- .setLevel(Level.DEBUG)
- .setMessage(new ParameterizedMessage("Testing {}", new TestObj()))
- .setThreadName("threadName")
- .setTimeMillis(1)
- .build();
- final String str = layout.toSerializable(expected);
- final String expectedMessage = "Testing " + TestObj.TO_STRING_VALUE;
- assertTrue(str.contains("\"message\":\"" + expectedMessage + '"'), str);
- final Log4jLogEvent actual =
- new Log4jJsonObjectMapper(propertiesAsList, true, false, false).readValue(str, Log4jLogEvent.class);
- assertEquals(expectedMessage, actual.getMessage().getFormattedMessage());
- }
-
- // Test for LOG4J2-2345
- @Test
- public void testReusableLayoutMessageWithCurlyBraces() throws Exception {
- final boolean propertiesAsList = false;
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(false)
- .setProperties(false)
- .setPropertiesAsList(propertiesAsList)
- .setComplete(false)
- .setCompact(true)
- .setEventEol(false)
- .setCharset(StandardCharsets.UTF_8)
- .setIncludeStacktrace(true)
- .build();
- final ReusableMessageFactory factory = ReusableMessageFactory.INSTANCE;
- final Message message = factory.newMessage("Testing {}", new TestObj());
- try {
- final Log4jLogEvent expected = Log4jLogEvent.newBuilder()
- .setLoggerName("a.B")
- .setLoggerFqcn("f.q.c.n")
- .setLevel(Level.DEBUG)
- .setMessage(message)
- .setThreadName("threadName")
- .setTimeMillis(1)
- .build();
- final MutableLogEvent mutableLogEvent = new MutableLogEvent();
- mutableLogEvent.initFrom(expected);
- final String str = layout.toSerializable(mutableLogEvent);
- final String expectedMessage = "Testing " + TestObj.TO_STRING_VALUE;
- assertTrue(str.contains("\"message\":\"" + expectedMessage + '"'), str);
- final Log4jLogEvent actual =
- new Log4jJsonObjectMapper(propertiesAsList, true, false, false).readValue(str, Log4jLogEvent.class);
- assertEquals(expectedMessage, actual.getMessage().getFormattedMessage());
- } finally {
- factory.recycle(message);
- }
- }
-
- // Test for LOG4J2-2312 LOG4J2-2341
- @Test
- public void testLayoutRingBufferEventReusableMessageWithCurlyBraces() throws Exception {
- final boolean propertiesAsList = false;
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setLocationInfo(false)
- .setProperties(false)
- .setPropertiesAsList(propertiesAsList)
- .setComplete(false)
- .setCompact(true)
- .setEventEol(false)
- .setCharset(StandardCharsets.UTF_8)
- .setIncludeStacktrace(true)
- .build();
- final ReusableMessageFactory factory = ReusableMessageFactory.INSTANCE;
- final Message message = factory.newMessage("Testing {}", new TestObj());
- try {
- final RingBufferLogEvent ringBufferEvent = new RingBufferLogEvent();
- ringBufferEvent.setValues(
- null,
- "a.B",
- null,
- "f.q.c.n",
- Level.DEBUG,
- message,
- null,
- new SortedArrayStringMap(),
- ThreadContext.EMPTY_STACK,
- 1L,
- "threadName",
- 1,
- null,
- new SystemClock(),
- new DummyNanoClock());
- final String str = layout.toSerializable(ringBufferEvent);
- final String expectedMessage = "Testing " + TestObj.TO_STRING_VALUE;
- assertThat(str, containsString("\"message\":\"" + expectedMessage + '"'));
- final Log4jLogEvent actual =
- new Log4jJsonObjectMapper(propertiesAsList, true, false, false).readValue(str, Log4jLogEvent.class);
- assertEquals(expectedMessage, actual.getMessage().getFormattedMessage());
- } finally {
- factory.recycle(message);
- }
- }
-
- static class TestObj {
- static final String TO_STRING_VALUE = "This is my toString {} with curly braces";
-
- @Override
- public String toString() {
- return TO_STRING_VALUE;
- }
- }
-
- @Test
- public void testLocationOffCompactOffMdcOff() throws Exception {
- this.testAllFeatures(false, false, false, null, false, false, true);
- }
-
- @Test
- public void testLocationOnCompactOnEventEolOnMdcOn() throws Exception {
- this.testAllFeatures(true, true, true, null, true, false, true);
- }
-
- @Test
- public void testLocationOnCompactOnEventEolOnMdcOnMdcAsList() throws Exception {
- this.testAllFeatures(true, true, true, null, true, true, true);
- }
-
- @Test
- public void testLocationOnCompactOnMdcOn() throws Exception {
- this.testAllFeatures(true, true, false, null, true, false, true);
- }
-
- @Test
- public void testObjectMessageAsJsonObject() {
- final String str = prepareJsonForObjectMessageAsJsonObjectTests(1234, true);
- assertTrue(str.contains("\"message\":{\"value\":1234}"), str);
- }
-
- @Test
- public void testObjectMessageAsJsonString() {
- final String str = prepareJsonForObjectMessageAsJsonObjectTests(1234, false);
- assertTrue(str.contains("\"message\":\"" + this.getClass().getCanonicalName() + "$TestClass@"), str);
- }
-
- @Test
- public void testStacktraceAsNonString() throws Exception {
- final String str = prepareJsonForStacktraceTests(false);
- assertTrue(str.contains("\"extendedStackTrace\":["), str);
- }
-
- @Test
- public void testStacktraceAsString() throws Exception {
- final String str = prepareJsonForStacktraceTests(true);
- assertTrue(str.contains("\"extendedStackTrace\":\"java.lang.NullPointerException"), str);
- }
-
- private String toPropertySeparator(final boolean compact) {
- return compact ? ":" : " : ";
- }
-
- /**
- * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2749">LOG4J2-2749</a>
- */
- @Test
- public void testEmptyValuesAreIgnored() {
- final AbstractJacksonLayout layout = JsonLayout.newBuilder()
- .setAdditionalFields(new KeyValuePair[] {new KeyValuePair("empty", "${ctx:empty:-}")})
- .setConfiguration(ctx.getConfiguration())
- .build();
- final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
- assertFalse(str.contains("\"empty\""), str);
- }
-
- /**
- * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-3358">LOG4J2-3358</a>
- */
- @Test
- public void jsonLayout_should_substitute_lookups() {
-
- // Create the layout.
- final KeyValuePair[] additionalFields = {new KeyValuePair("who", "${ctx:WHO}")};
- final JsonLayout layout = JsonLayout.newBuilder()
- .setConfiguration(new DefaultConfiguration())
- .setAdditionalFields(additionalFields)
- .build();
-
- // Create a log event containing `WHO` key in MDC.
- final StringMap contextData = ContextDataFactory.createContextData();
- contextData.putValue("WHO", "mduft");
- final LogEvent logEvent =
- Log4jLogEvent.newBuilder().setContextData(contextData).build();
-
- // Verify the `WHO` key.
- final String serializedLogEvent = layout.toSerializable(logEvent);
- assertThat(serializedLogEvent, containsString("\"who\" : \"mduft\""));
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/ThrowableProxyJsonTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/ThrowableProxyJsonTest.java
deleted file mode 100644
index 2fcc02d30d..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/layout/ThrowableProxyJsonTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.layout;
-
-import java.io.IOException;
-import org.apache.logging.log4j.jackson.ThrowableProxyJacksonTest;
-import org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper;
-import org.junit.Test;
-
-public class ThrowableProxyJsonTest extends ThrowableProxyJacksonTest {
-
- @Test
- public void testIoContainerAsJson() throws IOException {
- testIoContainer(new Log4jJsonObjectMapper());
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/parser/JsonLogEventParserTest.java b/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/parser/JsonLogEventParserTest.java
deleted file mode 100644
index b0a01efde8..0000000000
--- a/log4j-layout-jackson-json/src/test/java/org/apache/logging/log4j/jackson/json/parser/JsonLogEventParserTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jackson.json.parser;
-
-import java.nio.charset.StandardCharsets;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.parser.ParseException;
-import org.apache.logging.log4j.core.test.parser.AbstractLogEventParserTest;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JsonLogEventParserTest extends AbstractLogEventParserTest {
-
- private static final String JSON = "{\n" + " \"timeMillis\" : 1493121664118,\n"
- + " \"instant\":{\"epochSecond\":1493121664,\"nanoOfSecond\":118000000},\n"
- + " \"thread\" : \"main\",\n"
- + " \"threadId\" : 1,\n"
- + " \"threadPriority\" : 5,\n"
- + " \"level\" : \"INFO\",\n"
- + " \"loggerName\" : \"HelloWorld\",\n"
- + " \"marker\" : {\n"
- + " \"name\" : \"child\",\n"
- + " \"parents\" : [ {\n"
- + " \"name\" : \"parent\",\n"
- + " \"parents\" : [ {\n"
- + " \"name\" : \"grandparent\"\n"
- + " } ]\n"
- + " } ]\n"
- + " },\n"
- + " \"message\" : \"Hello, world!\",\n"
- + " \"thrown\" : {\n"
- + " \"commonElementCount\" : 0,\n"
- + " \"message\" : \"error message\",\n"
- + " \"name\" : \"java.lang.RuntimeException\",\n"
- + " \"extendedStackTrace\" : [ {\n"
- + " \"class\" : \"logtest.Main\",\n"
- + " \"method\" : \"main\",\n"
- + " \"file\" : \"Main.java\",\n"
- + " \"line\" : 29,\n"
- + " \"exact\" : true,\n"
- + " \"location\" : \"classes/\",\n"
- + " \"version\" : \"?\"\n"
- + " } ]\n"
- + " },\n"
- + " \"contextStack\" : [ \"one\", \"two\" ],\n"
- + " \"loggerFqcn\" : \"org.apache.logging.log4j.spi.AbstractLogger\",\n"
- + " \"endOfBatch\" : false,\n"
- + " \"contextMap\" : {\n"
- + " \"bar\" : \"BAR\",\n"
- + " \"foo\" : \"FOO\"\n"
- + " },\n"
- + " \"source\" : {\n"
- + " \"class\" : \"logtest.Main\",\n"
- + " \"method\" : \"main\",\n"
- + " \"file\" : \"Main.java\",\n"
- + " \"line\" : 29\n"
- + " }\n"
- + "}";
-
- private JsonLogEventParser parser;
-
- @Before
- public void setup() {
- parser = new JsonLogEventParser();
- }
-
- @Test
- public void testByteArray() throws ParseException {
- final LogEvent logEvent = parser.parseFrom(JSON.getBytes(StandardCharsets.UTF_8));
- assertLogEvent(logEvent);
- }
-
- @Test
- public void testByteArrayOffsetLength() throws ParseException {
- final byte[] bytes = ("abc" + JSON + "def").getBytes(StandardCharsets.UTF_8);
- final LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
- assertLogEvent(logEvent);
- }
-
- @Test
- public void testEmptyObject() throws ParseException {
- parser.parseFrom("{}");
- }
-
- @Test
- public void testString() throws ParseException {
- final LogEvent logEvent = parser.parseFrom(JSON);
- assertLogEvent(logEvent);
- }
-
- @Test(expected = ParseException.class)
- public void testStringEmpty() throws ParseException {
- parser.parseFrom("");
- }
-
- @Test
- public void testStringIgnoreInvalidProperty() throws ParseException {
- parser.parseFrom("{\"foo\":\"bar\"}");
- }
-
- @Test(expected = ParseException.class)
- public void testStringInvalidJson() throws ParseException {
- parser.parseFrom("foobar");
- }
-
- @Test(expected = ParseException.class)
- public void testStringJsonArray() throws ParseException {
- parser.parseFrom("[]");
- }
-
- @Test(expected = ParseException.class)
- public void testStringWrongPropertyType() throws ParseException {
- parser.parseFrom("{\"threadId\":\"foobar\"}");
- }
-}
diff --git a/log4j-layout-jackson-json/src/test/resources/log4j2-json-layout-timestamp.xml b/log4j-layout-jackson-json/src/test/resources/log4j2-json-layout-timestamp.xml
deleted file mode 100644
index 35190a3669..0000000000
--- a/log4j-layout-jackson-json/src/test/resources/log4j2-json-layout-timestamp.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to you under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<Configuration status="INFO">
- <Appenders>
- <List name="List">
- <JsonLayout compact="true" eventEol="true" includeTimeMillis="true"/>
- </List>
- </Appenders>
-
- <Loggers>
- <Root level="INFO">
- <AppenderRef ref="List"/>
- </Root>
- </Loggers>
-</Configuration>
diff --git a/log4j-layout-jackson-json/src/test/resources/log4j2-json-layout.xml b/log4j-layout-jackson-json/src/test/resources/log4j2-json-layout.xml
deleted file mode 100644
index 93f1ef5351..0000000000
--- a/log4j-layout-jackson-json/src/test/resources/log4j2-json-layout.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to you under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<Configuration status="INFO">
- <Appenders>
- <File name="stdout" ignoreExceptions="false" fileName="target/test-json-layout.log" append="false">
- <JsonLayout compact="true" eventEol="true" />
- </File>
- </Appenders>
-
- <Loggers>
- <Root level="INFO">
- <AppenderRef ref="stdout" />
- </Root>
- </Loggers>
-</Configuration>
diff --git a/log4j-layout-jackson-xml/src/test/java/org/apache/logging/log4j/jackson/xml/StackTraceElementXmlMixInTest.java b/log4j-layout-jackson-xml/src/test/java/org/apache/logging/log4j/jackson/xml/StackTraceElementXmlMixInTest.java
index ca658abc7e..407d764b9f 100644
--- a/log4j-layout-jackson-xml/src/test/java/org/apache/logging/log4j/jackson/xml/StackTraceElementXmlMixInTest.java
+++ b/log4j-layout-jackson-xml/src/test/java/org/apache/logging/log4j/jackson/xml/StackTraceElementXmlMixInTest.java
@@ -28,7 +28,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-@Category(Layouts.Json.class)
+@Category(Layouts.Xml.class)
public class StackTraceElementXmlMixInTest {
protected String aposToQuotes(final String json) {
diff --git a/log4j-layout-template-json-test/pom.xml b/log4j-layout-template-json-test/pom.xml
index fabafdbe60..c4084624ee 100644
--- a/log4j-layout-template-json-test/pom.xml
+++ b/log4j-layout-template-json-test/pom.xml
@@ -55,12 +55,6 @@
<artifactId>log4j-core-test</artifactId>
<scope>test</scope>
</dependency>
- <!-- needed for `JsonLayoutTest` -->
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson-json</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java
index ba57d1e4e7..55f351a9ce 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java
@@ -32,7 +32,8 @@ import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-@Disabled("")
+@Disabled(
+ "`co.elastic.logging.log4j2.EcsLayout` requires `org.apache.logging.log4j.core.layout.AbstractStringLayout#getStringBuilder()`, which doesn't exist anymore")
class EcsLayoutTest {
private static final Configuration CONFIGURATION = new DefaultConfiguration();
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonLayoutTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonLayoutTest.java
deleted file mode 100644
index 5952d0309a..0000000000
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/JsonLayoutTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.layout.template.json;
-
-import static org.apache.logging.log4j.layout.template.json.TestHelpers.serializeUsingLayout;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.jackson.json.layout.JsonLayout;
-import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-class JsonLayoutTest {
-
- private static final Configuration CONFIGURATION = new DefaultConfiguration();
-
- private static final JsonTemplateLayout JSON_TEMPLATE_LAYOUT = JsonTemplateLayout.newBuilder()
- .setConfiguration(CONFIGURATION)
- .setEventTemplateUri("classpath:JsonLayout.json")
- .build();
-
- private static final JsonLayout JSON_LAYOUT = JsonLayout.newBuilder()
- .setConfiguration(CONFIGURATION)
- .setProperties(true)
- .build();
-
- @Test
- void test_lite_log_events() {
- final List<LogEvent> logEvents = LogEventFixture.createLiteLogEvents(1_000);
- test(logEvents);
- }
-
- @Test
- void test_full_log_events() {
- final List<LogEvent> logEvents = LogEventFixture.createFullLogEvents(1_000);
- test(logEvents);
- }
-
- private static void test(final Collection<LogEvent> logEvents) {
- for (final LogEvent logEvent : logEvents) {
- test(logEvent);
- }
- }
-
- private static void test(final LogEvent logEvent) {
- final Map<String, Object> jsonTemplateLayoutMap = renderUsingJsonTemplateLayout(logEvent);
- final Map<String, Object> jsonLayoutMap = renderUsingJsonLayout(logEvent);
- // `JsonLayout` blindly serializes the `Throwable` as a POJO, this is, to say the least, quite wrong, and I
- // ain't going to try to emulate this behaviour in `JsonTemplateLayout`.
- // Hence, discarding the "thrown" field.
- jsonTemplateLayoutMap.remove("thrown");
- jsonLayoutMap.remove("thrown");
- // When the log event doesn't have any MDC, `JsonLayout` still emits an empty `contextMap` field, whereas
- // `JsonTemplateLayout` totally skips it.
- // Removing `contextMap` field to avoid discrepancies when there is no MDC to render.
- if (logEvent.getContextData().isEmpty()) {
- jsonLayoutMap.remove("contextMap");
- }
- Assertions.assertThat(jsonTemplateLayoutMap).isEqualTo(jsonLayoutMap);
- }
-
- private static Map<String, Object> renderUsingJsonTemplateLayout(final LogEvent logEvent) {
- return serializeUsingLayout(logEvent, JSON_TEMPLATE_LAYOUT);
- }
-
- private static Map<String, Object> renderUsingJsonLayout(final LogEvent logEvent) {
- return serializeUsingLayout(logEvent, JSON_LAYOUT);
- }
-}
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
index 1034346841..6f882cea1b 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
@@ -62,10 +62,13 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
+@Disabled(
+ "`co.elastic.logging.log4j2.EcsLayout` requires `org.apache.logging.log4j.core.layout.AbstractStringLayout#getStringBuilder()`, which doesn't exist anymore")
@Execution(ExecutionMode.SAME_THREAD)
class LogstashIT {
diff --git a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/UrisTest.java b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/UrisTest.java
index 32c59f3ab5..970c50d4ca 100644
--- a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/UrisTest.java
+++ b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/UrisTest.java
@@ -34,7 +34,7 @@ class UrisTest {
@Test
void testClassPathResource() {
- final String content = Uris.readUri("classpath:JsonLayout.json", StandardCharsets.US_ASCII);
+ final String content = Uris.readUri("classpath:EcsLayout.json", StandardCharsets.US_ASCII);
Assertions.assertThat(content).startsWith("{");
}
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
index 30a668b311..692bd70452 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.StringLayout;
import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.layout.ByteBufferDestination;
import org.apache.logging.log4j.core.layout.Encoder;
@@ -249,6 +250,11 @@ public class JsonTemplateLayout implements StringLayout {
return CONTENT_FORMAT;
}
+ public static JsonTemplateLayout createDefaultLayout() {
+ final DefaultConfiguration configuration = new DefaultConfiguration();
+ return JsonTemplateLayout.newBuilder().setConfiguration(configuration).build();
+ }
+
@Factory
@SuppressWarnings("WeakerAccess")
public static Builder newBuilder() {
diff --git a/log4j-layout-template-json/src/main/resources/JsonLayout.json b/log4j-layout-template-json/src/main/resources/JsonLayout.json
deleted file mode 100644
index 6f21011cf3..0000000000
--- a/log4j-layout-template-json/src/main/resources/JsonLayout.json
+++ /dev/null
@@ -1,87 +0,0 @@
-{
- "instant": {
- "epochSecond": {
- "$resolver": "timestamp",
- "epoch": {
- "unit": "secs",
- "rounded": true
- }
- },
- "nanoOfSecond": {
- "$resolver": "timestamp",
- "epoch": {
- "unit": "secs.nanos"
- }
- }
- },
- "thread": {
- "$resolver": "thread",
- "field": "name"
- },
- "level": {
- "$resolver": "level",
- "field": "name"
- },
- "loggerName": {
- "$resolver": "logger",
- "field": "name"
- },
- "message": {
- "$resolver": "message",
- "stringified": true
- },
- "thrown": {
- "message": {
- "$resolver": "exception",
- "field": "message"
- },
- "name": {
- "$resolver": "exception",
- "field": "className"
- },
- "extendedStackTrace": {
- "$resolver": "exception",
- "field": "stackTrace"
- }
- },
- "contextMap": {
- "$resolver": "mdc",
- "stringified": true
- },
- "contextStack": {
- "$resolver": "ndc"
- },
- "endOfBatch": {
- "$resolver": "endOfBatch"
- },
- "loggerFqcn": {
- "$resolver": "logger",
- "field": "fqcn"
- },
- "threadId": {
- "$resolver": "thread",
- "field": "id"
- },
- "threadPriority": {
- "$resolver": "thread",
- "field": "priority"
- },
- "source": {
- "class": {
- "$resolver": "source",
- "field": "className"
- },
- "method": {
- "$resolver": "source",
- "field": "methodName"
- },
- "file": {
- "$resolver": "source",
- "field": "fileName"
- },
- "line": {
- "$resolver": "source",
- "field": "lineNumber"
- }
- }
-}
diff --git a/log4j-perf/pom.xml b/log4j-perf/pom.xml
index b74e5c6dc1..99041932cd 100644
--- a/log4j-perf/pom.xml
+++ b/log4j-perf/pom.xml
@@ -57,10 +57,6 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jdbc</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson-json</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-layout-template-json</artifactId>
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmark.java
index 919739e10f..2c26294dc1 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmark.java
@@ -43,16 +43,6 @@ import org.openjdk.jmh.annotations.Benchmark;
*/
public class JsonTemplateLayoutBenchmark {
- @Benchmark
- public static int fullJtl4JsonLayout(final JsonTemplateLayoutBenchmarkState state) {
- return benchmark(state, state.getJtl4JsonLayout(), state.getFullLogEvents());
- }
-
- @Benchmark
- public static int liteJtl4JsonLayout(final JsonTemplateLayoutBenchmarkState state) {
- return benchmark(state, state.getJtl4JsonLayout(), state.getLiteLogEvents());
- }
-
@Benchmark
public static int fullJtl4EcsLayout(final JsonTemplateLayoutBenchmarkState state) {
return benchmark(state, state.getJtl4EcsLayout(), state.getFullLogEvents());
@@ -63,26 +53,6 @@ public class JsonTemplateLayoutBenchmark {
return benchmark(state, state.getJtl4EcsLayout(), state.getLiteLogEvents());
}
- @Benchmark
- public static int fullDefaultJsonLayout(final JsonTemplateLayoutBenchmarkState state) {
- return benchmark(state, state.getDefaultJsonLayout(), state.getFullLogEvents());
- }
-
- @Benchmark
- public static int liteDefaultJsonLayout(final JsonTemplateLayoutBenchmarkState state) {
- return benchmark(state, state.getDefaultJsonLayout(), state.getLiteLogEvents());
- }
-
- @Benchmark
- public static int fullCustomJsonLayout(final JsonTemplateLayoutBenchmarkState state) {
- return benchmark(state, state.getCustomJsonLayout(), state.getFullLogEvents());
- }
-
- @Benchmark
- public static int liteCustomJsonLayout(final JsonTemplateLayoutBenchmarkState state) {
- return benchmark(state, state.getCustomJsonLayout(), state.getLiteLogEvents());
- }
-
@Benchmark
public static int fullEcsLayout(final JsonTemplateLayoutBenchmarkState state) {
return benchmark(state, state.getEcsLayout(), state.getFullLogEvents());
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmarkState.java b/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmarkState.java
index e870071be4..d9afc4071e 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmarkState.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutBenchmarkState.java
@@ -25,8 +25,6 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.layout.ByteBufferDestination;
-import org.apache.logging.log4j.core.util.KeyValuePair;
-import org.apache.logging.log4j.jackson.json.layout.JsonLayout;
import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalField;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
@@ -42,14 +40,8 @@ public class JsonTemplateLayoutBenchmarkState {
private final ByteBufferDestination byteBufferDestination;
- private final Layout jtl4JsonLayout;
-
private final Layout jtl4EcsLayout;
- private final Layout defaultJsonLayout;
-
- private final Layout customJsonLayout;
-
private final Layout ecsLayout;
private final List<LogEvent> fullLogEvents;
@@ -60,23 +52,12 @@ public class JsonTemplateLayoutBenchmarkState {
public JsonTemplateLayoutBenchmarkState() {
this.byteBufferDestination = new BlackHoleByteBufferDestination(1024 * 512);
- this.jtl4JsonLayout = createJtl4JsonLayout();
this.jtl4EcsLayout = createJtl4EcsLayout();
- this.defaultJsonLayout = createDefaultJsonLayout();
- this.customJsonLayout = createCustomJsonLayout();
this.ecsLayout = createEcsLayout();
this.fullLogEvents = LogEventFixture.createFullLogEvents(LOG_EVENT_COUNT);
this.liteLogEvents = LogEventFixture.createLiteLogEvents(LOG_EVENT_COUNT);
}
- private static JsonTemplateLayout createJtl4JsonLayout() {
- return JsonTemplateLayout.newBuilder()
- .setConfiguration(CONFIGURATION)
- .setCharset(CHARSET)
- .setEventTemplateUri("classpath:JsonLayout.json")
- .build();
- }
-
private static JsonTemplateLayout createJtl4EcsLayout() {
final EventTemplateAdditionalField[] additionalFields = new EventTemplateAdditionalField[] {
EventTemplateAdditionalField.newBuilder()
@@ -92,21 +73,6 @@ public class JsonTemplateLayoutBenchmarkState {
.build();
}
- private static JsonLayout createDefaultJsonLayout() {
- return JsonLayout.newBuilder()
- .setConfiguration(CONFIGURATION)
- .setCharset(CHARSET)
- .build();
- }
-
- private static JsonLayout createCustomJsonLayout() {
- return JsonLayout.newBuilder()
- .setConfiguration(CONFIGURATION)
- .setCharset(CHARSET)
- .setAdditionalFields(new KeyValuePair[] {new KeyValuePair("@version", "\"1\"")})
- .build();
- }
-
private static EcsLayout createEcsLayout() {
final EcsLayout layout = EcsLayout.newBuilder()
.setConfiguration(CONFIGURATION)
@@ -126,22 +92,10 @@ public class JsonTemplateLayoutBenchmarkState {
return byteBufferDestination;
}
- Layout getJtl4JsonLayout() {
- return jtl4JsonLayout;
- }
-
Layout getJtl4EcsLayout() {
return jtl4EcsLayout;
}
- Layout getDefaultJsonLayout() {
- return defaultJsonLayout;
- }
-
- Layout getCustomJsonLayout() {
- return customJsonLayout;
- }
-
Layout getEcsLayout() {
return ecsLayout;
}
diff --git a/pom.xml b/pom.xml
index 2d9416555a..83c80a9991 100644
--- a/pom.xml
+++ b/pom.xml
@@ -225,8 +225,13 @@
</mailingLists>
- <!-- Modules in alphabetical order: -->
<modules>
+
+ <!-- the parent POM must come first: -->
+ <module>log4j-parent</module>
+
+ <!-- Last comes the rest of the modules in alphabetical order.
+ Note that modules here must have a corresponding entry in `dependencyManagement > dependencies` block below! -->
<module>log4j-1.2-api</module>
<module>log4j-api</module>
<module>log4j-api-test</module>
@@ -248,7 +253,6 @@
<module>log4j-jul</module>
<module>log4j-kubernetes</module>
<module>log4j-layout-jackson</module>
- <module>log4j-layout-jackson-json</module>
<module>log4j-layout-jackson-xml</module>
<module>log4j-layout-template-json</module>
<module>log4j-layout-template-json-test</module>
@@ -264,6 +268,7 @@
<module>log4j-spring-cloud-config</module>
<module>log4j-to-jul</module>
<module>log4j-to-slf4j</module>
+
</modules>
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">
@@ -443,12 +448,6 @@
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-layout-jackson-json</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-layout-jackson-xml</artifactId>
diff --git a/src/site/asciidoc/manual/appenders.adoc b/src/site/asciidoc/manual/appenders.adoc
index 82917550d4..c2127cf344 100644
--- a/src/site/asciidoc/manual/appenders.adoc
+++ b/src/site/asciidoc/manual/appenders.adoc
@@ -1181,7 +1181,7 @@ Here is a sample HttpAppender configuration snippet:
<Appenders>
<Http name="Http" url="https://localhost:9200/test/log4j/">
<Property name="X-Java-Runtime" value="$${java:runtime}" />
- <JsonLayout properties="true"/>
+ <JsonTemplateLayout/>
<SSL>
<KeyStore location="log4j2-keystore.jks" passwordEnvironmentVariable="KEYSTORE_PASSWORD"/>
<TrustStore location="truststore.jks" passwordFile="${sys:user.home}/truststore.pwd"/>
@@ -3315,7 +3315,7 @@ This is an unsecured TCP configuration:
<Configuration status="warn" name="MyApp">
<Appenders>
<Socket name="socket" host="localhost" port="9500">
- <JsonLayout properties="true"/>
+ <JsonTemplateLayout/>
</Socket>
</Appenders>
<Loggers>
@@ -3334,7 +3334,7 @@ This is a secured link:#SSL[SSL] configuration:
<Configuration status="warn" name="MyApp">
<Appenders>
<Socket name="socket" host="localhost" port="9500">
- <JsonLayout properties="true"/>
+ <JsonTemplateLayout/>
<SSL>
<KeyStore location="log4j2-keystore.jks" passwordEnvironmentVariable="KEYSTORE_PASSWORD"/>
<TrustStore location="truststore.jks" passwordFile="${sys:user.home}/truststore.pwd"/>
diff --git a/src/site/asciidoc/manual/json-template-layout.adoc.vm b/src/site/asciidoc/manual/json-template-layout.adoc.vm
index d2a2cfa586..f517785b4a 100644
--- a/src/site/asciidoc/manual/json-template-layout.adoc.vm
+++ b/src/site/asciidoc/manual/json-template-layout.adoc.vm
@@ -423,13 +423,6 @@ artifact, which contains the following predefined event templates:
information, while the latter is Google's expected place for the exception,
and integrates with https://cloud.google.com/error-reporting[Google Error Reporting].
-- https://github.com/apache/logging-log4j2/tree/master/log4j-layout-template-json/src/main/resources/JsonLayout.json[`JsonLayout.json`]
- providing the exact JSON structure generated by link:layouts.html#JSONLayout[`JsonLayout`]
- with the exception of `thrown` field. (`JsonLayout` serializes the `Throwable`
- as is via Jackson `ObjectMapper`, whereas `JsonLayout.json` template of
- `JsonTemplateLayout` employs the `StackTraceElementLayout.json` template
- for stack traces to generate a document-store-friendly flat structure.)
-
[#event-template-resolvers]
==== Event Template Resolvers
@@ -1881,77 +1874,63 @@ Below is a feature comparison matrix between `JsonTemplateLayout` and
alternatives.
.Feature comparison matrix
-[cols="3,1,1,1,1"]
+[cols="3,1,1"]
|===
| Feature
| `JsonTemplateLayout`
-| link:layouts.html#JSONLayout[`JsonLayout`]
| https://github.com/elastic/java-ecs-logging/tree/master/log4j2-ecs-layout[`EcsLayout`]
| Java version
| 8
-| 8
| 6
| Dependencies
| None
-| Jackson
| None
| Schema customization?
| ✓
| ✕
-| ✕
| Timestamp customization?
| ✓
| ✕
-| ✕
| (Almost) garbage-free?
| ✓
-| ✕
| ✓
| Custom typed `Message` serialization?
| ✓
-| ✕
| ?footnote:[Only for ``ObjectMessage``s and if Jackson is in the classpath.]
| Custom typed `MDC` value serialization?
| ✓
| ✕
-| ✕
| Rendering stack traces as array?
| ✓
| ✓
-| ✓
| Stack trace truncation?
| ✓
| ✕
-| ✕
| JSON pretty print?
| ✕
-| ✓
| ✕
| Additional string fields?
| ✓
| ✓
-| ✓
| Additional JSON fields?
| ✓
| ✕
-| ✕
| Custom resolvers?
| ✓
| ✕
-| ✕
|===
[#faq]
diff --git a/src/site/asciidoc/manual/layouts.adoc b/src/site/asciidoc/manual/layouts.adoc
index 361fa21a7e..0b7f74ab0e 100644
--- a/src/site/asciidoc/manual/layouts.adoc
+++ b/src/site/asciidoc/manual/layouts.adoc
@@ -232,188 +232,6 @@ Configure as follows to use dataPattern and timezone in HtmlLayout:
</Appenders>
----
-[#JSONLayout]
-== JSON Layout
-
-**Note:** JsonTemplate is considered deprecated. JsonTemplateLayout provides more capabilitites and
-should be used instead.
-
-Appends a series of JSON events as strings serialized as bytes.
-
-=== Complete well-formed JSON vs. fragment JSON
-
-If you configure `complete="true"`, the appender outputs a well-formed
-JSON document. By default, with `complete="false"`, you should include
-the output as an _external file_ in a separate file to form a
-well-formed JSON document.
-
-If `complete="false"`, the appender does not write the JSON open array
-character "[" at the start of the document, "]" and the end, nor comma
-"," between records.
-
-Log event follows this pattern:
-
-[source,json]
-----
-{
- "instant" : {
- "epochSecond" : 1493121664,
- "nanoOfSecond" : 118000000
- },
- "thread" : "main",
- "level" : "INFO",
- "loggerName" : "HelloWorld",
- "marker" : {
- "name" : "child",
- "parents" : [ {
- "name" : "parent",
- "parents" : [ {
- "name" : "grandparent"
- } ]
- } ]
- },
- "message" : "Hello, world!",
- "thrown" : {
- "commonElementCount" : 0,
- "message" : "error message",
- "name" : "java.lang.RuntimeException",
- "extendedStackTrace" : [ {
- "class" : "logtest.Main",
- "method" : "main",
- "file" : "Main.java",
- "line" : 29,
- "exact" : true,
- "location" : "classes/",
- "version" : "?"
- } ]
- },
- "contextStack" : [ "one", "two" ],
- "endOfBatch" : false,
- "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
- "contextMap" : {
- "bar" : "BAR",
- "foo" : "FOO"
- },
- "threadId" : 1,
- "threadPriority" : 5,
- "source" : {
- "class" : "logtest.Main",
- "method" : "main",
- "file" : "Main.java",
- "line" : 29
- }
-}
-----
-
-If `complete="false"`, the appender does not write the JSON open array
-character "[" at the start of the document, "]" and the end, nor comma
-"," between records.
-
-=== Pretty vs. compact JSON
-
-The compact attribute determines whether the output will be "pretty" or not. The default value is "false",
-which means the appender uses end-of-line characters and indents lines to format the text. If
-`compact="true"`, then no end-of-line or indentation is used, which will cause the output
-to take less space. Of course, the message content may contain, escaped end-of-lines.
-
-.JsonLayout Parameters
-[cols="1m,1,4"]
-|===
-|Parameter Name |Type |Description
-
-|charset
-|String
-|The character set to use when converting to a byte
-array. The value must be a valid
-http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html[Charset].
-If not specified, UTF-8 will be used.
-
-|compact
-|boolean
-|If true, the appender does not use end-of-lines and
-indentation. Defaults to false.
-
-|eventEol
-|boolean
-|If true, the appender appends an end-of-line after
-each record. Defaults to false. Use with eventEol=true and compact=true
-to get one record per line.
-
-|endOfLine
-|String
-|If set, overrides the default end-of-line string. E.g. set it to "\n" and use with eventEol=true and compact=true to have one record per line separated by "\n" instead of "\r\n". Defaults to null (i.e. not set).
-
-|complete
-|boolean
-|If true, the appender includes the JSON header and
-footer, and comma between records. Defaults to false.
-
-|properties
-|boolean
-|If true, the appender includes the thread context
-map in the generated JSON. Defaults to false.
-
-|propertiesAsList
-|boolean
-|If true, the thread context map is included
-as a list of map entry objects, where each entry has a "key" attribute
-(whose value is the key) and a "value" attribute (whose value is the
-value). Defaults to false, in which case the thread context map is
-included as a simple map of key-value pairs.
-
-|locationInfo
-|boolean
-a|
-If true, the appender includes the location information in the generated
-JSON. Defaults to false.
-
-Generating link:#LocationInformation[location information] is an
-expensive operation and may impact performance. Use with caution.
-
-|includeStacktrace
-|boolean
-|If true, include full stacktrace of any logged
-https://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html[Throwable]
-(optional, default to true).
-
-|includeTimeMillis
-|boolean
-|If true, the timeMillis attribute is included in the Json payload instead of the instant. timeMillis
-will contain the number of milliseconds since midnight, January 1, 1970 UTC.
-
-|stacktraceAsString
-|boolean
-|Whether to format the stacktrace as a
-string, and not a nested object (optional, defaults to false).
-
-|includeNullDelimiter
-|boolean
-|Whether to include NULL byte as
-delimiter after each event (optional, default to false).
-
-|objectMessageAsJsonObject
-|boolean
-|If true, ObjectMessage is
-serialized as JSON object to the "message" field of the output log.
-Defaults to false.
-|===
-
-To include any custom field in the output, use following syntax:
-
-[source,xml]
-----
-<JsonLayout>
- <KeyValuePair key="additionalField1" value="constant value"/>
- <KeyValuePair key="additionalField2" value="$${ctx:key}"/>
-</JsonLayout>
-----
-
-Custom fields are always last, in the order they are declared. The
-values support link:lookups.html[lookups].
-
-Additional link:../runtime-dependencies.html[runtime dependencies] are
-required for using JsonLayout.
-
[#JSONTemplateLayout]
== JSON Template Layout
@@ -1925,8 +1743,7 @@ using Java Serialization. The SerializedLayout accepts no parameters.
This layout is deprecated since version 2.9. Java Serialization has
inherent security weaknesses, using this layout is no longer
-recommended. An alternative layout containing the same information is
-link:#JSONLayout[JsonLayout], configured with `properties="true"`.
+recommended.
[#SyslogLayout]
== Syslog Layout
diff --git a/src/site/asciidoc/manual/lookups.adoc b/src/site/asciidoc/manual/lookups.adoc
index 65f3b9285b..d1c4edf902 100644
--- a/src/site/asciidoc/manual/lookups.adoc
+++ b/src/site/asciidoc/manual/lookups.adoc
@@ -101,11 +101,11 @@ Log4j Docker provides access to the following container attributes:
|===
----
-<JsonLayout properties="true" compact="true" eventEol="true">
- <KeyValuePair key="containerId" value="${docker:containerId}"/>
- <KeyValuePair key="containerName" value="${docker:containerName}"/>
- <KeyValuePair key="imageName" value="${docker:imageName}"/>
-</JsonLayout>
+<JsonTemplateLayout>
+ <EventTemplateAdditionalField key="containerId" value="${docker:containerId}"/>
+ <EventTemplateAdditionalField key="containerName" value="${docker:containerName}"/>
+ <EventTemplateAdditionalField key="imageName" value="${docker:imageName}"/>
+</JsonTemplateLayout>
----
This Lookup is subject to the requirements listed at link:../log4j-docker/index.html[Log4j Docker Support]
diff --git a/src/site/asciidoc/runtime-dependencies.adoc b/src/site/asciidoc/runtime-dependencies.adoc
index c8c90fc356..8200cc987f 100644
--- a/src/site/asciidoc/runtime-dependencies.adoc
+++ b/src/site/asciidoc/runtime-dependencies.adoc
@@ -487,9 +487,6 @@ the exact list of JAR files needed for these features.
|CSV Layout
|https://commons.apache.org/proper/commons-csv/[Apache Commons CSV]
-|JSON Layout
-|https://github.com/FasterXML/jackson[Jackson core and databind]
-
|XML Layout
|https://github.com/FasterXML/jackson[Jackson core, databind and dataformat XML] and `com.fasterxml.woodstox:woodstox-core:5.0.2`
diff --git a/src/site/site.xml b/src/site/site.xml
index 44faa904dd..de19364f95 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -172,7 +172,6 @@
<item name="Layouts" href="/manual/layouts.html" collapse="true">
<item name="CSV" href="/manual/layouts.html#CSVLayouts"/>
<item name="HTML" href="/manual/layouts.html#HTMLLayout"/>
- <item name="JSON" href="/manual/layouts.html#JSONLayout"/>
<item name="JSON Template" href="/manual/json-template-layout.html"/>
<item name="Pattern" href="/manual/layouts.html#PatternLayout"/>
<item name="RFC-5424" href="/manual/layouts.html#RFC5424Layout"/>