http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java new file mode 100644 index 0000000..9d86f6e --- /dev/null +++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java @@ -0,0 +1,173 @@ +/* + * 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.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +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.categories.Layouts; +import org.apache.logging.log4j.core.CoreLoggerContexts; +import org.apache.logging.log4j.core.selector.ContextSelector; +import org.apache.logging.log4j.core.selector.CoreContextSelectors; +import org.apache.logging.log4j.junit.CleanFiles; +import org.apache.logging.log4j.junit.LoggerContextRule; +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" XML file a.k.a. a well-formed XML file. + */ +@RunWith(Parameterized.class) +@Category(Layouts.Xml.class) +public class XmlCompleteFileAppenderTest { + + public XmlCompleteFileAppenderTest(final Class<ContextSelector> contextSelector) { + this.loggerContextRule = new LoggerContextRule("XmlCompleteFileAppenderTest.xml", contextSelector); + this.cleanFiles = new CleanFiles(logFile); + this.ruleChain = RuleChain.outerRule(cleanFiles).around(loggerContextRule); + } + + @Parameters(name = "{0}") + public static Class<?>[] getParameters() { + return CoreContextSelectors.CLASSES; + } + + private final File logFile = new File("target", "XmlCompleteFileAppenderTest.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=false"; + logger.info(logMsg); + CoreLoggerContexts.stopLoggerContext(false, logFile); // stop async thread + + String line1; + String line2; + String line3; + String line4; + String line5; + try (final BufferedReader reader = new BufferedReader(new FileReader(logFile))) { + line1 = reader.readLine(); + line2 = reader.readLine(); + reader.readLine(); // ignore the empty line after the <Events> root + line3 = reader.readLine(); + line4 = reader.readLine(); + line5 = reader.readLine(); + } finally { + logFile.delete(); + } + assertNotNull("line1", line1); + final String msg1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; + assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + ']', line1.equals(msg1)); + + assertNotNull("line2", line2); + final String msg2 = "<Events xmlns=\"http://logging.apache.org/log4j/2.0/events\">"; + assertTrue("line2 incorrect: [" + line2 + "], does not contain: [" + msg2 + ']', line2.equals(msg2)); + + assertNotNull("line3", line3); + final String msg3 = "<Event "; + assertTrue("line3 incorrect: [" + line3 + "], does not contain: [" + msg3 + ']', line3.contains(msg3)); + + assertNotNull("line4", line4); + final String msg4 = "<Instant epochSecond="; + assertTrue("line4 incorrect: [" + line4 + "], does not contain: [" + msg4 + ']', line4.contains(msg4)); + + assertNotNull("line5", line5); + final String msg5 = logMsg; + assertTrue("line5 incorrect: [" + line5 + "], does not contain: [" + msg5 + ']', line5.contains(msg5)); + + final String location = "testFlushAtEndOfBatch"; + assertTrue("no location", !line1.contains(location)); + } + + /** + * Test the indentation of the Events XML. + * <p>Expected Events XML is as below.</p> + * <pre> +<?xml version="1.0" encoding="UTF-8"?> +<Events xmlns="http://logging.apache.org/log4j/2.0/events"> + + <Event xmlns="http://logging.apache.org/log4j/2.0/events" thread="main" level="INFO" loggerName="com.foo.Bar" endOfBatch="true" loggerFqcn="org.apache.logging.log4j.spi.AbstractLogger" threadId="12" threadPriority="5"> + <Instant epochSecond="1515889414" nanoOfSecond="144000000" epochMillisecond="1515889414144" nanoOfMillisecond="0"/> + <Message>First Msg tag must be in level 2 after correct indentation</Message> + </Event> + + <Event xmlns="http://logging.apache.org/log4j/2.0/events" thread="main" level="INFO" loggerName="com.foo.Bar" endOfBatch="true" loggerFqcn="org.apache.logging.log4j.spi.AbstractLogger" threadId="12" threadPriority="5"> + <Instant epochSecond="1515889414" nanoOfSecond="144000000" epochMillisecond="1515889414144" nanoOfMillisecond="0"/> + <Message>Second Msg tag must also be in level 2 after correct indentation</Message> + </Event> +</Events> + * </pre> + * @throws Exception + */ + @Test + public void testChildElementsAreCorrectlyIndented() throws Exception { + final Logger logger = this.loggerContextRule.getLogger("com.foo.Bar"); + final String firstLogMsg = "First Msg tag must be in level 2 after correct indentation"; + logger.info(firstLogMsg); + final String secondLogMsg = "Second Msg tag must also be in level 2 after correct indentation"; + logger.info(secondLogMsg); + CoreLoggerContexts.stopLoggerContext(false, logFile); // stop async thread + + int[] indentations = { + 0, //"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 0, //"<Events xmlns=\"http://logging.apache.org/log4j/2.0/events\">\n" + -1, // empty + 2, //" <Event xmlns=\"http://logging.apache.org/log4j/2.0/events\" thread=\"main\" level=\"INFO\" loggerName=\"com.foo.Bar\" endOfBatch=\"true\" loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\" threadId=\"12\" threadPriority=\"5\">\n" + 4, //" <Instant epochSecond=\"1515889414\" nanoOfSecond=\"144000000\" epochMillisecond=\"1515889414144\" nanoOfMillisecond=\"0\"/>\n" + 4, //" <Message>First Msg tag must be in level 2 after correct indentation</Message>\n" + + 2, //" </Event>\n" + -1, // empty + 2, //" <Event xmlns=\"http://logging.apache.org/log4j/2.0/events\" thread=\"main\" level=\"INFO\" loggerName=\"com.foo.Bar\" endOfBatch=\"true\" loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\" threadId=\"12\" threadPriority=\"5\">\n" + + 4, //" <Instant epochSecond=\"1515889414\" nanoOfSecond=\"144000000\" epochMillisecond=\"1515889414144\" nanoOfMillisecond=\"0\"/>\n" + + 4, //" <Message>Second Msg tag must also be in level 2 after correct indentation</Message>\n" + + 2, //" </Event>\n" + + 0, //"</Events>\n"; + }; + List<String> lines1 = Files.readAllLines(logFile.toPath(), Charset.forName("UTF-8")); + + assertEquals("number of lines", indentations.length, lines1.size()); + for (int i = 0; i < indentations.length; i++) { + String line = lines1.get(i); + if (line.trim().isEmpty()) { + assertEquals(-1, indentations[i]); + } else { + String padding = " ".substring(0, indentations[i]); + assertTrue("Expected " + indentations[i] + " leading spaces but got: " + line, line.startsWith(padding)); + } + } + } +}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java new file mode 100644 index 0000000..107ef22 --- /dev/null +++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java @@ -0,0 +1,76 @@ +/* + * 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.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.categories.Layouts; +import org.apache.logging.log4j.core.CoreLoggerContexts; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Tests a "complete" XML file a.k.a. a well-formed XML file. + */ +@Category(Layouts.Xml.class) +public class XmlFileAppenderTest { + + @BeforeClass + public static void beforeClass() { + System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, + "XmlFileAppenderTest.xml"); + } + + @Test + public void testFlushAtEndOfBatch() throws Exception { + final File file = new File("target", "XmlFileAppenderTest.log"); + // System.out.println(f.getAbsolutePath()); + file.delete(); + final Logger log = LogManager.getLogger("com.foo.Bar"); + final String logMsg = "Message flushed with immediate flush=false"; + log.info(logMsg); + CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread + + List<String> lines = Files.readAllLines(file.toPath(), Charset.forName("UTF8")); + file.delete(); + + String[] expect = { + "", // ? unsure why initial empty line... + "<Event ", // + "<Instant epochSecond=", // + logMsg, // + "</Event>", // + }; + + for (int i = 0; i < expect.length; i++) { + assertTrue("Expected line " + i + " to contain " + expect[i] + " but got: " + lines.get(i), + lines.get(i).contains(expect[i])); + } + + final String location = "testFlushAtEndOfBatch"; + assertTrue("no location", !lines.get(0).contains(location)); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java new file mode 100644 index 0000000..1794160 --- /dev/null +++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java @@ -0,0 +1,90 @@ +/* + * 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.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.categories.Layouts; +import org.apache.logging.log4j.core.CoreLoggerContexts; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Tests a "complete" XML file a.k.a. a well-formed XML file. + */ +@Category(Layouts.Xml.class) +public class XmlRandomAccessFileAppenderTest { + + @BeforeClass + public static void beforeClass() { + System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, + "XmlRandomAccessFileAppenderTest.xml"); + } + + @Test + @Ignore + public void testFlushAtEndOfBatch() throws Exception { + final File file = new File("target", "XmlRandomAccessFileAppenderTest.log"); + // System.out.println(f.getAbsolutePath()); + file.delete(); + final Logger log = LogManager.getLogger("com.foo.Bar"); + final String logMsg = "Message flushed with immediate flush=false"; + log.info(logMsg); + CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread + + String line1; + String line2; + String line3; + String line4; + try (final BufferedReader reader = new BufferedReader(new FileReader(file))) { + line1 = reader.readLine(); + line2 = reader.readLine(); + line3 = reader.readLine(); + line4 = reader.readLine(); + } finally { + file.delete(); + } + assertNotNull("line1", line1); + final String msg1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; + assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + ']', line1.equals(msg1)); + + assertNotNull("line2", line2); + final String msg2 = "<log4j:events xmlns:log4j=\"http://logging.apache.org/log4j/\">"; + assertTrue("line2 incorrect: [" + line2 + "], does not contain: [" + msg2 + ']', line2.equals(msg2)); + + assertNotNull("line3", line3); + final String msg3 = "<log4j:event "; + assertTrue("line3 incorrect: [" + line3 + "], does not contain: [" + msg3 + ']', line3.contains(msg3)); + + assertNotNull("line4", line4); + final String msg4 = logMsg; + assertTrue("line4 incorrect: [" + line4 + "], does not contain: [" + msg4 + ']', line4.contains(msg4)); + + final String location = "testFlushAtEndOfBatch"; + assertTrue("no location", !line1.contains(location)); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml index b791acc..196e4e5 100644 --- a/log4j-core/pom.xml +++ b/log4j-core/pom.xml @@ -279,12 +279,6 @@ <artifactId>groovy-all</artifactId> <scope>test</scope> </dependency> - <!-- Used for testing HttpAppender --> - <dependency> - <groupId>com.github.tomakehurst</groupId> - <artifactId>wiremock</artifactId> - <scope>test</scope> - </dependency> <!-- GC-free --> <dependency> <groupId>com.google.code.java-allocation-instrumenter</groupId> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java deleted file mode 100644 index 85dd21e..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java +++ /dev/null @@ -1,57 +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.jackson; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import org.apache.logging.log4j.core.impl.ContextDataFactory; -import org.apache.logging.log4j.util.StringMap; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class ContextDataAsEntryListDeserializer extends StdDeserializer<StringMap> { - - private static final long serialVersionUID = 1L; - - ContextDataAsEntryListDeserializer() { - super(Map.class); - } - - @Override - public StringMap deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, - JsonProcessingException { - final List<MapEntry> list = jp.readValueAs(new TypeReference<List<MapEntry>>() { - // empty - }); - final StringMap contextData = new ContextDataFactory().createContextData(); - for (final MapEntry mapEntry : list) { - contextData.putValue(mapEntry.getKey(), mapEntry.getValue()); - } - return contextData; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListSerializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListSerializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListSerializer.java deleted file mode 100644 index ccf17ff..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListSerializer.java +++ /dev/null @@ -1,58 +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.jackson; - -import java.io.IOException; -import java.util.Map; - -import org.apache.logging.log4j.util.ReadOnlyStringMap; -import org.apache.logging.log4j.util.BiConsumer; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class ContextDataAsEntryListSerializer extends StdSerializer<ReadOnlyStringMap> { - - private static final long serialVersionUID = 1L; - - protected ContextDataAsEntryListSerializer() { - super(Map.class, false); - } - - @Override - public void serialize(final ReadOnlyStringMap contextData, final JsonGenerator jgen, final SerializerProvider provider) - throws IOException, JsonGenerationException { - - final MapEntry[] pairs = new MapEntry[contextData.size()]; - contextData.forEach(new BiConsumer<String, Object>() { - int i = 0; - - @Override - public void accept(final String key, final Object value) { - pairs[i++] = new MapEntry(key, String.valueOf(value)); - } - }); - jgen.writeObject(pairs); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java deleted file mode 100644 index 3a9a13e..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java +++ /dev/null @@ -1,65 +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.jackson; - -import java.io.IOException; -import java.util.Map; - -import org.apache.logging.log4j.core.impl.ContextDataFactory; -import org.apache.logging.log4j.util.StringMap; - -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.deser.std.StdDeserializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class ContextDataDeserializer extends StdDeserializer<StringMap> { - - private static final long serialVersionUID = 1L; - - ContextDataDeserializer() { - super(Map.class); - } - - @Override - public StringMap deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, - JsonProcessingException { - - // Sanity check: verify that we got "Json Object": -// JsonToken tok = jp.nextToken(); -// if (tok != JsonToken.START_OBJECT) { -// throw new IOException("Expected data to start with an Object"); -// } - final StringMap contextData = ContextDataFactory.createContextData(); - // Iterate over object fields: - while (jp.nextToken() != JsonToken.END_OBJECT) { - final String fieldName = jp.getCurrentName(); - - // move to value - jp.nextToken(); - contextData.putValue(fieldName, jp.getText()); - } - return contextData; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java deleted file mode 100644 index 8808d3d..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java +++ /dev/null @@ -1,64 +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.jackson; - -import java.io.IOException; -import java.util.Map; - -import org.apache.logging.log4j.util.ReadOnlyStringMap; -import org.apache.logging.log4j.util.TriConsumer; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class ContextDataSerializer extends StdSerializer<ReadOnlyStringMap> { - - private static final long serialVersionUID = 1L; - - protected ContextDataSerializer() { - super(Map.class, false); - } - - @Override - public void serialize(final ReadOnlyStringMap contextData, final JsonGenerator jgen, - final SerializerProvider provider) throws IOException, JsonGenerationException { - - jgen.writeStartObject(); - contextData.forEach(WRITE_STRING_FIELD_INTO, jgen); - jgen.writeEndObject(); - } - - private static final TriConsumer<String, Object, JsonGenerator> WRITE_STRING_FIELD_INTO = - new TriConsumer<String, Object, JsonGenerator>() { - - @Override - public void accept(final String key, final Object value, final JsonGenerator jsonGenerator) { - try { - jsonGenerator.writeStringField(key, String.valueOf(value)); - } catch (final Exception ex) { - throw new IllegalStateException("Problem with key " + key, ex); - } - } - }; -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java deleted file mode 100644 index 84df3d6..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java +++ /dev/null @@ -1,90 +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.jackson; - -import java.io.Serializable; - -import org.apache.logging.log4j.core.impl.ExtendedClassInfo; -import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -/** - * Mix-in for {@link ExtendedStackTraceElement}. - */ -@JsonPropertyOrder({ "class", "method", "file", "line", "exact", "location", "version" }) -abstract class ExtendedStackTraceElementMixIn implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonCreator - public ExtendedStackTraceElementMixIn( - // @formatter:off - @JsonProperty("class") final String declaringClass, - @JsonProperty("method") final String methodName, - @JsonProperty("file") final String fileName, - @JsonProperty("line") final int lineNumber, - @JsonProperty("exact") final boolean exact, - @JsonProperty("location") final String location, - @JsonProperty("version") final String version - // @formatter:on - ) { - // empty - } - - @JsonProperty("class") - @JacksonXmlProperty(localName = "class", isAttribute = true) - public abstract String getClassName(); - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public abstract boolean getExact(); - - @JsonIgnore - public abstract ExtendedClassInfo getExtraClassInfo(); - - @JsonProperty("file") - @JacksonXmlProperty(localName = "file", isAttribute = true) - public abstract String getFileName(); - - @JsonProperty("line") - @JacksonXmlProperty(localName = "line", isAttribute = true) - public abstract int getLineNumber(); - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public abstract String getLocation(); - - @JsonProperty("method") - @JacksonXmlProperty(localName = "method", isAttribute = true) - public abstract String getMethodName(); - - @JsonIgnore - abstract StackTraceElement getStackTraceElement(); - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public abstract String getVersion(); - - @JsonIgnore - public abstract boolean isNativeMethod(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java deleted file mode 100644 index 3bc3447..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java +++ /dev/null @@ -1,98 +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.jackson; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.ThreadContext.ContextStack; -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.message.Message; -import org.apache.logging.log4j.message.ObjectMessage; - -import com.fasterxml.jackson.databind.Module.SetupContext; -import com.fasterxml.jackson.databind.module.SimpleModule; -import org.apache.logging.log4j.core.time.Instant; - -/** - * Initialization utils. - * <p> - * <em>Consider this class private.</em> - * </p> - */ -class Initializers { - - /** - * Used to set up {@link SetupContext} from different {@link SimpleModule}s. - */ - static class SetupContextInitializer { - - 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, LogEventWithContextListMixIn.class); - // 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); - } - } - - /** - * Used to set up {@link SetupContext} from different {@link SimpleModule}s. - * Differs from SetupContextInitializer by installing {@code LogEventJsonMixIn} for LogEvents, - * not {@code LogEventMixIn}, so it handles ThreadContext serialization differently. - */ - static class SetupContextJsonInitializer { - - 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); - } - } - - /** - * Used to set up {@link SimpleModule} from different {@link SimpleModule} subclasses. - */ - static class SimpleModuleInitializer { - void initialize(final SimpleModule simpleModule, final boolean objectMessageAsJsonObject) { - // Workaround because mix-ins do not work for classes that already have a built-in deserializer. - // See Jackson issue 429. - simpleModule.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer()); - simpleModule.addDeserializer(ContextStack.class, new MutableThreadContextStackDeserializer()); - if (objectMessageAsJsonObject) { - simpleModule.addSerializer(ObjectMessage.class, new ObjectMessageSerializer()); - } - simpleModule.addSerializer(Message.class, new MessageSerializer()); - } - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java deleted file mode 100644 index 216534b..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java +++ /dev/null @@ -1,53 +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.jackson; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.time.Instant; - -/** - * Jackson mix-in for {@link Instant}. - * <p> - * <em>Consider this class private.</em> - * </p> - * @see Marker - */ -@JsonIgnoreProperties({ "epochMillisecond", "nanoOfMillisecond" }) -abstract class InstantMixIn { - - @JsonCreator - InstantMixIn( - // @formatter:off - @JsonProperty("epochSecond") final long epochSecond, - @JsonProperty("nanoOfSecond") final int nanoOfSecond) - // @formatter:on - { - // empty - } - - @JsonProperty("epochSecond") - @JacksonXmlProperty(localName = "epochSecond", isAttribute = true) - abstract long getEpochSecond(); - - @JsonProperty("nanoOfSecond") - @JacksonXmlProperty(localName = "nanoOfSecond", isAttribute = true) - abstract int getNanoOfSecond(); -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/JsonConstants.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/JsonConstants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/JsonConstants.java deleted file mode 100644 index bb9898d..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/JsonConstants.java +++ /dev/null @@ -1,35 +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.jackson; - -/** - * Keeps constants separate from any class that may depend on third party jars. - */ -public final class JsonConstants { - public static final String ELT_CAUSE = "cause"; - public static final String ELT_CONTEXT_MAP = "contextMap"; - public static final String ELT_CONTEXT_STACK = "contextStack"; - public static final String ELT_MARKER = "marker"; - public static final String ELT_PARENTS = "parents"; - public static final String ELT_SOURCE = "source"; - public static final String ELT_SUPPRESSED = "suppressed"; - public static final String ELT_THROWN = "thrown"; - public static final String ELT_MESSAGE = "message"; - public static final String ELT_EXTENDED_STACK_TRACE = "extendedStackTrace"; - public static final String ELT_NANO_TIME = "nanoTime"; - public static final String ELT_INSTANT = "instant"; -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LevelMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LevelMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LevelMixIn.java deleted file mode 100644 index bb252c8..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LevelMixIn.java +++ /dev/null @@ -1,44 +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.jackson; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Jackson mix-in for {@link Level}. - * <p> - * <em>Consider this class private.</em> - * </p> - * @see Marker - */ -@JsonIgnoreProperties({ "name", "declaringClass", "standardLevel" }) -abstract class LevelMixIn { - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static Level getLevel(final String name) { - return null; - } - - @JsonValue - public abstract String name(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntryDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntryDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntryDeserializer.java deleted file mode 100644 index 0a7281e..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntryDeserializer.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.core.jackson; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class ListOfMapEntryDeserializer extends StdDeserializer<Map<String, String>> { - - private static final long serialVersionUID = 1L; - - ListOfMapEntryDeserializer() { - super(Map.class); - } - - @Override - public Map<String, String> deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, - JsonProcessingException { - final List<MapEntry> list = jp.readValueAs(new TypeReference<List<MapEntry>>() { - // empty - }); - final HashMap<String, String> map = new HashMap<>(list.size()); - for (final MapEntry mapEntry : list) { - map.put(mapEntry.getKey(), mapEntry.getValue()); - } - return map; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntrySerializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntrySerializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntrySerializer.java deleted file mode 100644 index 02f47a2..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ListOfMapEntrySerializer.java +++ /dev/null @@ -1,54 +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.jackson; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class ListOfMapEntrySerializer extends StdSerializer<Map<String, String>> { - - private static final long serialVersionUID = 1L; - - protected ListOfMapEntrySerializer() { - super(Map.class, false); - } - - @Override - public void serialize(final Map<String, String> map, final JsonGenerator jgen, final SerializerProvider provider) - throws IOException, JsonGenerationException { - final Set<Entry<String, String>> entrySet = map.entrySet(); - final MapEntry[] pairs = new MapEntry[entrySet.size()]; - int i = 0; - for (final Entry<String, String> entry : entrySet) { - pairs[i++] = new MapEntry(entry.getKey(), entry.getValue()); - } - jgen.writeObject(pairs); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonModule.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonModule.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonModule.java deleted file mode 100644 index ceb53b4..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/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.core.jackson; - -import org.apache.logging.log4j.core.jackson.Initializers.SetupContextInitializer; -import org.apache.logging.log4j.core.jackson.Initializers.SetupContextJsonInitializer; -import org.apache.logging.log4j.core.jackson.Initializers.SimpleModuleInitializer; - -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.module.SimpleModule; - -/** - * <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; - private final boolean objectMessageAsJsonObject; - - 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; - this.objectMessageAsJsonObject = objectMessageAsJsonObject; - // MUST init 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 SetupContextJsonInitializer().setupModule(context, includeStacktrace, stacktraceAsString); - } - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonObjectMapper.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonObjectMapper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonObjectMapper.java deleted file mode 100644 index 4997c91..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jJsonObjectMapper.java +++ /dev/null @@ -1,47 +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.jackson; - -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}. - */ - 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); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jStackTraceElementDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jStackTraceElementDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jStackTraceElementDeserializer.java deleted file mode 100644 index 936ace1..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jStackTraceElementDeserializer.java +++ /dev/null @@ -1,82 +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.jackson; - -import java.io.IOException; - -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.deser.std.StdScalarDeserializer; - -/** - * Copy and edit the Jackson (Apache License 2.0) class to use Log4j attribute names. Does not work as of Jackson 2.3.2. - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public final class Log4jStackTraceElementDeserializer extends StdScalarDeserializer<StackTraceElement> { - private static final long serialVersionUID = 1L; - - /** - * Constructs a new initialized instance. - */ - public Log4jStackTraceElementDeserializer() { - 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 = null, methodName = null, fileName = null; - 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 { - // An XML number always comes in a string since there is no syntax help as with JSON. - try { - lineNumber = Integer.parseInt(jp.getText().trim()); - } catch (final NumberFormatException e) { - throw JsonMappingException.from(jp, "Non-numeric token (" + t + ") for property 'line'", e); - } - } - } else if ("method".equals(propName)) { - methodName = jp.getText(); - } else if ("nativeMethod".equals(propName)) { - // no setter, not passed via constructor: ignore - } else { - this.handleUnknownProperty(jp, ctxt, this._valueClass, propName); - } - } - return new StackTraceElement(className, methodName, fileName, lineNumber); - } - throw ctxt.mappingException(this._valueClass, t); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlModule.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlModule.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlModule.java deleted file mode 100644 index 34f0f68..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlModule.java +++ /dev/null @@ -1,50 +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.jackson; - -import org.apache.logging.log4j.core.jackson.Initializers.SetupContextInitializer; -import org.apache.logging.log4j.core.jackson.Initializers.SimpleModuleInitializer; - -import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -final class Log4jXmlModule extends JacksonXmlModule { - - private static final long serialVersionUID = 1L; - private final boolean includeStacktrace; - private final boolean stacktraceAsString; - - Log4jXmlModule(final boolean includeStacktrace, final boolean stacktraceAsString) { - super(); - this.includeStacktrace = includeStacktrace; - this.stacktraceAsString = stacktraceAsString; - // MUST init here. - // Calling this from setupModule is too late! - new SimpleModuleInitializer().initialize(this, false); - } - - @Override - public void setupModule(final SetupContext context) { - // Calling super is a MUST! - super.setupModule(context); - new SetupContextInitializer().setupModule(context, includeStacktrace, stacktraceAsString); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlObjectMapper.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlObjectMapper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlObjectMapper.java deleted file mode 100644 index b390a3f..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jXmlObjectMapper.java +++ /dev/null @@ -1,48 +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.jackson; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; - -/** - * A Jackson XML {@link ObjectMapper} initialized for Log4j. - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class Log4jXmlObjectMapper extends XmlMapper { - - private static final long serialVersionUID = 1L; - - /** - * Create a new instance using the {@link Log4jXmlModule}. - */ - public Log4jXmlObjectMapper() { - this(true, false); - } - - /** - * Create a new instance using the {@link Log4jXmlModule}. - */ - public Log4jXmlObjectMapper(final boolean includeStacktrace, final boolean stacktraceAsString) { - super(new Log4jXmlModule(includeStacktrace, stacktraceAsString)); - this.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java deleted file mode 100644 index c7b92f0..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java +++ /dev/null @@ -1,59 +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.jackson; - -import org.apache.logging.log4j.core.jackson.Initializers.SetupContextInitializer; -import org.apache.logging.log4j.core.jackson.Initializers.SetupContextJsonInitializer; -import org.apache.logging.log4j.core.jackson.Initializers.SimpleModuleInitializer; - -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.module.SimpleModule; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -final class Log4jYamlModule extends SimpleModule { - - private static final long serialVersionUID = 1L; - private final boolean encodeThreadContextAsList; - private final boolean includeStacktrace; - private final boolean stacktraceAsString; - - Log4jYamlModule(final boolean encodeThreadContextAsList, final boolean includeStacktrace, final boolean stacktraceAsString) { - super(Log4jYamlModule.class.getName(), new Version(2, 0, 0, null, null, null)); - this.encodeThreadContextAsList = encodeThreadContextAsList; - this.includeStacktrace = includeStacktrace; - this.stacktraceAsString = stacktraceAsString; - // MUST init here. - // Calling this from setupModule is too late! - //noinspection ThisEscapedInObjectConstruction - new SimpleModuleInitializer().initialize(this, false); - } - - @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 SetupContextJsonInitializer().setupModule(context, includeStacktrace, stacktraceAsString); - } - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java deleted file mode 100644 index 0b80591..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java +++ /dev/null @@ -1,48 +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.jackson; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; - -/** - * A Jackson {@link ObjectMapper} initialized for Log4j. - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public class Log4jYamlObjectMapper extends YAMLMapper { - - private static final long serialVersionUID = 1L; - - /** - * Create a new instance using the {@link Log4jYamlModule}. - */ - public Log4jYamlObjectMapper() { - this(false, true, false); - } - - /** - * Create a new instance using the {@link Log4jYamlModule}. - */ - public Log4jYamlObjectMapper(final boolean encodeThreadContextAsList, final boolean includeStacktrace, final boolean stacktraceAsString) { - this.registerModule(new Log4jYamlModule(encodeThreadContextAsList, includeStacktrace, stacktraceAsString)); - this.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java deleted file mode 100644 index bbb024d..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java +++ /dev/null @@ -1,156 +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.jackson; - -import java.util.Map; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.ThreadContext.ContextStack; -import org.apache.logging.log4j.core.time.Instant; -import org.apache.logging.log4j.util.ReadOnlyStringMap; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.message.Message; - -import com.fasterxml.jackson.annotation.JsonFilter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -@JsonRootName(XmlConstants.ELT_EVENT) -@JacksonXmlRootElement(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EVENT) -@JsonFilter("org.apache.logging.log4j.core.impl.Log4jLogEvent") -@JsonPropertyOrder({ "timeMillis", XmlConstants.ELT_INSTANT, "threadName", "level", "loggerName", "marker", "message", "thrown", XmlConstants.ELT_CONTEXT_MAP, - JsonConstants.ELT_CONTEXT_STACK, "loggerFQCN", "Source", "endOfBatch" }) -abstract class LogEventJsonMixIn implements LogEvent { - - private static final long serialVersionUID = 1L; - -// @JsonProperty(JsonConstants.ELT_CONTEXT_MAP) -// @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP) -// @JsonSerialize(using = MapSerializer.class) -// @JsonDeserialize(using = MapDeserializer.class) - @Override - @JsonIgnore -// @JsonProperty(JsonConstants.ELT_CONTEXT_MAP) -// @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP) - public abstract Map<String, String> getContextMap(); - - @JsonProperty(JsonConstants.ELT_CONTEXT_MAP) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP) - @JsonSerialize(using = ContextDataSerializer.class) - @JsonDeserialize(using = ContextDataDeserializer.class) - //@JsonIgnore - @Override - public abstract ReadOnlyStringMap getContextData(); - - @JsonProperty(JsonConstants.ELT_CONTEXT_STACK) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK_ITEM) - @Override - public abstract ContextStack getContextStack(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract Level getLevel(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract String getLoggerFqcn(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract String getLoggerName(); - - @JsonProperty(JsonConstants.ELT_MARKER) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER) - @Override - public abstract Marker getMarker(); - - @JsonProperty(JsonConstants.ELT_MESSAGE) - @JsonDeserialize(using = SimpleMessageDeserializer.class) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MESSAGE) - @Override - public abstract Message getMessage(); - - @JsonProperty(JsonConstants.ELT_SOURCE) - @JsonDeserialize(using = Log4jStackTraceElementDeserializer.class) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SOURCE) - @Override - public abstract StackTraceElement getSource(); - - @Override - @JsonProperty("threadId") - @JacksonXmlProperty(isAttribute = true, localName = "threadId") - public abstract long getThreadId(); - - @Override - @JsonProperty("thread") - @JacksonXmlProperty(isAttribute = true, localName = "thread") - public abstract String getThreadName(); - - @Override - @JsonProperty("threadPriority") - @JacksonXmlProperty(isAttribute = true, localName = "threadPriority") - public abstract int getThreadPriority(); - - @JsonIgnore - @Override - public abstract Throwable getThrown(); - - @JsonProperty(JsonConstants.ELT_THROWN) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_THROWN) - @Override - public abstract ThrowableProxy getThrownProxy(); - - @JsonIgnore // ignore from 2.11 -// @JsonProperty() -// @JacksonXmlProperty(isAttribute = true) - @Override - public abstract long getTimeMillis(); - - @JsonProperty(JsonConstants.ELT_INSTANT) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_INSTANT) - @Override - public abstract Instant getInstant(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract boolean isEndOfBatch(); - - @JsonIgnore - @Override - public abstract boolean isIncludeLocation(); - - @Override - public abstract void setEndOfBatch(boolean endOfBatch); - - @Override - public abstract void setIncludeLocation(boolean locationRequired); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java deleted file mode 100644 index 12b61fa..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java +++ /dev/null @@ -1,155 +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.jackson; - -import java.util.Map; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.ThreadContext.ContextStack; -import org.apache.logging.log4j.core.time.Instant; -import org.apache.logging.log4j.util.ReadOnlyStringMap; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.message.Message; - -import com.fasterxml.jackson.annotation.JsonFilter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -@JsonRootName(XmlConstants.ELT_EVENT) -@JacksonXmlRootElement(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EVENT) -@JsonFilter("org.apache.logging.log4j.core.impl.Log4jLogEvent") -@JsonPropertyOrder({ "timeMillis", XmlConstants.ELT_INSTANT, "threadName", "level", "loggerName", "marker", "message", "thrown", XmlConstants.ELT_CONTEXT_MAP, - JsonConstants.ELT_CONTEXT_STACK, "loggerFQCN", "Source", "endOfBatch" }) -abstract class LogEventWithContextListMixIn implements LogEvent { - - private static final long serialVersionUID = 1L; - -// @JsonProperty(JsonConstants.ELT_CONTEXT_MAP) -// @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP) -// @JsonSerialize(using = ListOfMapEntrySerializer.class) -// @JsonDeserialize(using = ListOfMapEntryDeserializer.class) - @Override - @JsonIgnore - public abstract Map<String, String> getContextMap(); - - @JsonProperty(JsonConstants.ELT_CONTEXT_MAP) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP) - @JsonSerialize(using = ContextDataAsEntryListSerializer.class) - @JsonDeserialize(using = ContextDataAsEntryListDeserializer.class) -// @JsonIgnore - @Override - public abstract ReadOnlyStringMap getContextData(); - - @JsonProperty(JsonConstants.ELT_CONTEXT_STACK) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK_ITEM) - @Override - public abstract ContextStack getContextStack(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract Level getLevel(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract String getLoggerFqcn(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract String getLoggerName(); - - @JsonProperty(JsonConstants.ELT_MARKER) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER) - @Override - public abstract Marker getMarker(); - - @JsonProperty(JsonConstants.ELT_MESSAGE) - @JsonSerialize(using = MessageSerializer.class) - @JsonDeserialize(using = SimpleMessageDeserializer.class) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MESSAGE) - @Override - public abstract Message getMessage(); - - @JsonProperty(JsonConstants.ELT_SOURCE) - @JsonDeserialize(using = Log4jStackTraceElementDeserializer.class) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SOURCE) - @Override - public abstract StackTraceElement getSource(); - - @Override - @JsonProperty("threadId") - @JacksonXmlProperty(isAttribute = true, localName = "threadId") - public abstract long getThreadId(); - - @Override - @JsonProperty("thread") - @JacksonXmlProperty(isAttribute = true, localName = "thread") - public abstract String getThreadName(); - - @Override - @JsonProperty("threadPriority") - @JacksonXmlProperty(isAttribute = true, localName = "threadPriority") - public abstract int getThreadPriority(); - - @JsonIgnore - @Override - public abstract Throwable getThrown(); - - @JsonProperty(JsonConstants.ELT_THROWN) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_THROWN) - @Override - public abstract ThrowableProxy getThrownProxy(); - - @JsonIgnore // ignore from 2.11 -// @JsonProperty() -// @JacksonXmlProperty(isAttribute = true) - @Override - public abstract long getTimeMillis(); - - @JsonProperty(JsonConstants.ELT_INSTANT) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_INSTANT) - @Override - public abstract Instant getInstant(); - - @JsonProperty() - @JacksonXmlProperty(isAttribute = true) - @Override - public abstract boolean isEndOfBatch(); - - @JsonIgnore - @Override - public abstract boolean isIncludeLocation(); - - @Override - public abstract void setEndOfBatch(boolean endOfBatch); - - @Override - public abstract void setIncludeLocation(boolean locationRequired); - -}