You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2017/07/26 19:34:10 UTC
[01/12] logging-log4j2 git commit: LOG4J2-1986 Public API for parsing
the output from JsonLayout/XmlLayout/YamlLayout into a LogEvent
Repository: logging-log4j2
Updated Branches:
refs/heads/master b464da6b0 -> 9576bbfe2
LOG4J2-1986 Public API for parsing the output from JsonLayout/XmlLayout/YamlLayout into a LogEvent
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c4814a87
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c4814a87
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c4814a87
Branch: refs/heads/master
Commit: c4814a8730eb24bdf89cf23c89b4a957b8418ba5
Parents: eea873e
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Sat Jul 22 22:48:24 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Sat Jul 22 22:48:24 2017 +0200
----------------------------------------------------------------------
.../parser/AbstractJacksonLogEventParser.java | 85 +++++++++++++++
.../log4j/core/parser/JsonLogEventParser.java | 32 ++++++
.../log4j/core/parser/LogEventParser.java | 64 ++++++++++++
.../log4j/core/parser/ParseException.java | 34 ++++++
.../log4j/core/parser/TextLogEventParser.java | 50 +++++++++
.../log4j/core/parser/XmlLogEventParser.java | 32 ++++++
.../log4j/core/parser/YamlLogEventParser.java | 33 ++++++
.../logging/log4j/core/parser/package-info.java | 20 ++++
.../core/parser/JsonLogEventParserTest.java | 103 +++++++++++++++++++
src/changes/changes.xml | 3 +
10 files changed, 456 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
new file mode 100644
index 0000000..8b00e57
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
@@ -0,0 +1,85 @@
+/*
+ * 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.parser;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectReader;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+class AbstractJacksonLogEventParser implements TextLogEventParser {
+ final ObjectReader objectReader;
+
+ AbstractJacksonLogEventParser(ObjectReader objectReader) {
+ this.objectReader = objectReader;
+ }
+
+ @Override
+ public LogEvent parseFrom(InputStream input) throws IOException, ParseException {
+ try {
+ return objectReader.readValue(input);
+ } catch (JsonProcessingException e) {
+ throw new ParseException(e);
+ }
+ }
+
+ @Override
+ public LogEvent parseFrom(Reader input) throws IOException, ParseException {
+ try {
+ return objectReader.readValue(input);
+ } catch (JsonProcessingException e) {
+ throw new ParseException(e);
+ }
+ }
+
+ @Override
+ public LogEvent parseFrom(String input) throws ParseException {
+ try {
+ return objectReader.readValue(input);
+ } catch (JsonProcessingException e) {
+ throw new ParseException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public LogEvent parseFrom(byte[] input) throws ParseException {
+ try {
+ return objectReader.readValue(input);
+ } catch (JsonProcessingException e) {
+ throw new ParseException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public LogEvent parseFrom(byte[] input, int offset, int length) throws ParseException {
+ try {
+ return objectReader.readValue(input, offset, length);
+ } catch (JsonProcessingException e) {
+ throw new ParseException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
new file mode 100644
index 0000000..218de0b
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
@@ -0,0 +1,32 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
+
+/**
+ * Parse the output from JsonLayout layout into instances of {@link LogEvent}.
+ */
+public class JsonLogEventParser extends AbstractJacksonLogEventParser {
+
+ public JsonLogEventParser() {
+ super(new Log4jJsonObjectMapper().readerFor(Log4jLogEvent.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
new file mode 100644
index 0000000..88e84fb
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
@@ -0,0 +1,64 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Parse the output from a layout into instances of {@link LogEvent}.
+ */
+public interface LogEventParser {
+
+ /**
+ * Parse from an InputStream. The input stream may contain multiple log events.
+ * This method will read one log event and leave the stream open and positioned to read the
+ * next log event.
+ *
+ * @param input the input stream
+ *
+ * @return the parsed LogEvent, or {@literal null} of end of input is reached.
+ * @throws IOException if unable to read from the input
+ * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
+ */
+ LogEvent parseFrom(InputStream input) throws IOException, ParseException;
+
+ /**
+ * Parse from a byte array, which is expected to contain exactly one log event.
+ *
+ * @param input the byte array
+ *
+ * @return the parsed LogEvent, never {@literal null}.
+ * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
+ */
+ LogEvent parseFrom(byte[] input) throws ParseException;
+
+ /**
+ * Parse from a specified range of a byte array. The specified range is expected to contain
+ * exactly one log event.
+ *
+ * @param input the byte array
+ * @param offset the initial offset
+ * @param length the length
+ *
+ * @return the parsed LogEvent, never {@literal null}.
+ * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
+ */
+ LogEvent parseFrom(byte[] input, int offset, int length) throws ParseException;
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
new file mode 100644
index 0000000..8f5fa54
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
@@ -0,0 +1,34 @@
+/*
+ * 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.parser;
+
+/**
+ * Thrown when the input cannot be parsed.
+ */
+public class ParseException extends Exception {
+ public ParseException(String message) {
+ super(message);
+ }
+
+ public ParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ParseException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
new file mode 100644
index 0000000..3428024
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
@@ -0,0 +1,50 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * Parse the output from a text based layout into instances of {@link LogEvent}.
+ */
+public interface TextLogEventParser extends LogEventParser {
+ /**
+ * Parse from a Reader. The reader may contain multiple log events.
+ * This method will read one log event and leave the reader open and positioned to read the
+ * next log event.
+ *
+ * @param input the reader
+ *
+ * @return the parsed LogEvent, or {@literal null} of end of input is reached.
+ * @throws IOException if unable to read from the input
+ * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
+ */
+ LogEvent parseFrom(Reader input) throws IOException, ParseException;
+
+ /**
+ * Parse from a String, which is expected to contain exactly one log event.
+ *
+ * @param input the string
+ *
+ * @return the parsed LogEvent
+ * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
+ */
+ LogEvent parseFrom(String input) throws ParseException;
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
new file mode 100644
index 0000000..597e70b
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
@@ -0,0 +1,32 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
+
+/**
+ * Parse the output from XmlLayout layout into instances of {@link LogEvent}.
+ */
+public class XmlLogEventParser extends AbstractJacksonLogEventParser {
+
+ public XmlLogEventParser() {
+ super(new Log4jXmlObjectMapper().readerFor(Log4jLogEvent.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
new file mode 100644
index 0000000..59b3463
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
@@ -0,0 +1,33 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
+import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
+
+/**
+ * Parse the output from YamlLayout layout into instances of {@link LogEvent}.
+ */
+public class YamlLogEventParser extends AbstractJacksonLogEventParser {
+
+ public YamlLogEventParser() {
+ super(new Log4jYamlObjectMapper().readerFor(Log4jLogEvent.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/package-info.java
new file mode 100644
index 0000000..3506570
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Parsers for the output of various layouts.
+ */
+package org.apache.logging.log4j.core.parser;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
new file mode 100644
index 0000000..5684602
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class JsonLogEventParserTest {
+
+ private JsonLogEventParser parser;
+
+ private static final String JSON = "{\n" +
+ " \"timeMillis\" : 1493121664118,\n" +
+ " \"thread\" : \"main\",\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" +
+ " \"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" +
+ " \"endOfBatch\" : false,\n" +
+ " \"loggerFqcn\" : \"org.apache.logging.log4j.spi.AbstractLogger\",\n" +
+ " \"contextMap\" : {\n" +
+ " \"bar\" : \"BAR\",\n" +
+ " \"foo\" : \"FOO\"\n" +
+ " },\n" +
+ " \"threadId\" : 1,\n" +
+ " \"threadPriority\" : 5,\n" +
+ " \"source\" : {\n" +
+ " \"class\" : \"logtest.Main\",\n" +
+ " \"method\" : \"main\",\n" +
+ " \"file\" : \"Main.java\",\n" +
+ " \"line\" : 29\n" +
+ " }\n" +
+ "}";
+
+ @Before
+ public void setup() {
+ parser = new JsonLogEventParser();
+ }
+
+ @Test
+ public void testString() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(JSON);
+ assertNotNull(logEvent);
+ assertEquals("HelloWorld", logEvent.getLoggerName());
+ // TODO assert more here
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringEmpty() throws ParseException {
+ parser.parseFrom("");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringInvalidJson() throws ParseException {
+ parser.parseFrom("foobar");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringInvalidProperty() throws ParseException {
+ parser.parseFrom("{\"foo\":\"bar\"}");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c4814a87/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 074e31c..522f49b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
- "remove" - Removed
-->
<release version="2.9.0" date="2017-MM-DD" description="GA Release 2.9.0">
+ <action issue="LOG4J2-1986" dev="mikes" type="add">
+ Public API for parsing the output from JsonLayout/XmlLayout/YamlLayout into a LogEvent.
+ </action>
<action issue="LOG4J2-1984" dev="rgoers" type="update">
Allow maxLength of StructuredData to be specified by the user.
</action>
[12/12] logging-log4j2 git commit: LOG4J2-1986 Remove unused import
Posted by mi...@apache.org.
LOG4J2-1986 Remove unused import
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9576bbfe
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9576bbfe
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9576bbfe
Branch: refs/heads/master
Commit: 9576bbfe29f3a3a8b139f6628667883edd931d18
Parents: ab2d326
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Wed Jul 26 21:33:17 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Wed Jul 26 21:33:17 2017 +0200
----------------------------------------------------------------------
.../org/apache/logging/log4j/core/parser/YamlLogEventParser.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9576bbfe/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
index 51a2bfc..09815a9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
@@ -18,7 +18,6 @@ package org.apache.logging.log4j.core.parser;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
/**
[10/12] logging-log4j2 git commit: Merge branch 'master' into
LOG4J2-1986
Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1986
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b96f5220
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b96f5220
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b96f5220
Branch: refs/heads/master
Commit: b96f5220dbebf6e0a4fb9f7da07c3a9d7d443418
Parents: d3b7220 b464da6
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Wed Jul 26 20:41:41 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Wed Jul 26 20:41:41 2017 +0200
----------------------------------------------------------------------
.../logging/log4j/util/StringBuilders.java | 2 +-
.../logging/log4j/util/StringBuildersTest.java | 14 +
.../rolling/DefaultRolloverStrategy.java | 5 +-
.../rolling/DirectWriteRolloverStrategy.java | 5 +-
.../logging/log4j/core/tools/Generate.java | 1724 +++++++++---------
.../core/layout/AbstractStringLayoutTest.java | 29 +-
.../org/apache/logging/log4j/jul/ApiLogger.java | 12 +-
src/changes/changes.xml | 6 +
8 files changed, 925 insertions(+), 872 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b96f5220/src/changes/changes.xml
----------------------------------------------------------------------
[03/12] logging-log4j2 git commit: LOG4J2-1986 Unit tests for YAML
and XML
Posted by mi...@apache.org.
LOG4J2-1986 Unit tests for YAML and XML
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a5bb4987
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a5bb4987
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a5bb4987
Branch: refs/heads/master
Commit: a5bb49876cb0b9a2083d50fbb4904c9f15b959cb
Parents: 72d0d12
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Sun Jul 23 21:51:15 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Sun Jul 23 21:51:15 2017 +0200
----------------------------------------------------------------------
.../core/parser/JsonLogEventParserTest.java | 35 +----
.../log4j/core/parser/LogEventParserTest.java | 55 ++++++++
.../core/parser/XmlLogEventParserTest.java | 129 +++++++++++++++++++
.../core/parser/YamlLogEventParserTest.java | 123 ++++++++++++++++++
4 files changed, 308 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5bb4987/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
index f4efd91..5263704 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.logging.log4j.core.parser;
-import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.Before;
import org.junit.Test;
@@ -25,15 +24,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class JsonLogEventParserTest {
+public class JsonLogEventParserTest extends LogEventParserTest {
private JsonLogEventParser parser;
@@ -134,29 +126,4 @@ public class JsonLogEventParserTest {
assertLogEvent(logEvent);
}
- private void assertLogEvent(LogEvent logEvent) {
- assertThat(logEvent, is(notNullValue()));
- assertThat(logEvent.getTimeMillis(), equalTo(1493121664118L));
- assertThat(logEvent.getThreadName(), equalTo("main"));
- assertThat(logEvent.getThreadId(), equalTo(1L));
- assertThat(logEvent.getThreadPriority(), equalTo(5));
- assertThat(logEvent.getLevel(), equalTo(Level.INFO));
- assertThat(logEvent.getLoggerName(), equalTo("HelloWorld"));
- assertThat(logEvent.getMarker().getName(), equalTo("child"));
- assertThat(logEvent.getMarker().getParents()[0].getName(), equalTo("parent"));
- assertThat(logEvent.getMarker().getParents()[0].getParents()[0].getName(),
- equalTo("grandparent"));
- assertThat(logEvent.getMessage().getFormattedMessage(), equalTo("Hello, world!"));
- assertThat(logEvent.getThrown(), is(nullValue()));
- assertThat(logEvent.getThrownProxy().getMessage(), equalTo("error message"));
- assertThat(logEvent.getThrownProxy().getName(), equalTo("java.lang.RuntimeException"));
- assertThat(logEvent.getThrownProxy().getExtendedStackTrace()[0].getClassName(),
- equalTo("logtest.Main"));
- assertThat(logEvent.getLoggerFqcn(), equalTo("org.apache.logging.log4j.spi.AbstractLogger"));
- assertThat(logEvent.getContextStack().asList(), equalTo(Arrays.asList("one", "two")));
- assertThat((String) logEvent.getContextData().getValue("foo"), equalTo("FOO"));
- assertThat((String) logEvent.getContextData().getValue("bar"), equalTo("BAR"));
- assertThat(logEvent.getSource().getClassName(), equalTo("logtest.Main"));
- }
-
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5bb4987/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/LogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/LogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/LogEventParserTest.java
new file mode 100644
index 0000000..d995da0
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/LogEventParserTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LogEvent;
+
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public abstract class LogEventParserTest {
+ protected void assertLogEvent(LogEvent logEvent) {
+ assertThat(logEvent, is(notNullValue()));
+ assertThat(logEvent.getTimeMillis(), equalTo(1493121664118L));
+ assertThat(logEvent.getThreadName(), equalTo("main"));
+ assertThat(logEvent.getThreadId(), equalTo(1L));
+ assertThat(logEvent.getThreadPriority(), equalTo(5));
+ assertThat(logEvent.getLevel(), equalTo(Level.INFO));
+ assertThat(logEvent.getLoggerName(), equalTo("HelloWorld"));
+ assertThat(logEvent.getMarker().getName(), equalTo("child"));
+ assertThat(logEvent.getMarker().getParents()[0].getName(), equalTo("parent"));
+ assertThat(logEvent.getMarker().getParents()[0].getParents()[0].getName(),
+ equalTo("grandparent"));
+ assertThat(logEvent.getMessage().getFormattedMessage(), equalTo("Hello, world!"));
+ assertThat(logEvent.getThrown(), is(nullValue()));
+ assertThat(logEvent.getThrownProxy().getMessage(), equalTo("error message"));
+ assertThat(logEvent.getThrownProxy().getName(), equalTo("java.lang.RuntimeException"));
+ assertThat(logEvent.getThrownProxy().getExtendedStackTrace()[0].getClassName(),
+ equalTo("logtest.Main"));
+ assertThat(logEvent.getLoggerFqcn(), equalTo("org.apache.logging.log4j.spi.AbstractLogger"));
+ assertThat(logEvent.getContextStack().asList(), equalTo(Arrays.asList("one", "two")));
+ assertThat((String) logEvent.getContextData().getValue("foo"), equalTo("FOO"));
+ assertThat((String) logEvent.getContextData().getValue("bar"), equalTo("BAR"));
+ assertThat(logEvent.getSource().getClassName(), equalTo("logtest.Main"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5bb4987/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
new file mode 100644
index 0000000..802b7d4
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+
+public class XmlLogEventParserTest extends LogEventParserTest {
+
+ private XmlLogEventParser parser;
+
+ private static final String XML = "<Event xmlns=\"http://logging.apache.org/log4j/2.0/events\"\n" +
+ " timeMillis=\"1493121664118\"\n" +
+ " level=\"INFO\"\n" +
+ " loggerName=\"HelloWorld\"\n" +
+ " endOfBatch=\"false\"\n" +
+ " thread=\"main\"\n" +
+ " loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\"\n" +
+ " threadId=\"1\"\n" +
+ " threadPriority=\"5\">\n" +
+ " <Marker name=\"child\">\n" +
+ " <Parents>\n" +
+ " <Marker name=\"parent\">\n" +
+ " <Parents>\n" +
+ " <Marker name=\"grandparent\"/>\n" +
+ " </Parents>\n" +
+ " </Marker>\n" +
+ " </Parents>\n" +
+ " </Marker>\n" +
+ " <Message>Hello, world!</Message>\n" +
+ " <ContextMap>\n" +
+ " <item key=\"bar\" value=\"BAR\"/>\n" +
+ " <item key=\"foo\" value=\"FOO\"/>\n" +
+ " </ContextMap>\n" +
+ " <ContextStack>\n" +
+ " <ContextStackItem>one</ContextStackItem>\n" +
+ " <ContextStackItem>two</ContextStackItem>\n" +
+ " </ContextStack>\n" +
+ " <Source\n" +
+ " class=\"logtest.Main\"\n" +
+ " method=\"main\"\n" +
+ " file=\"Main.java\"\n" +
+ " line=\"29\"/>\n" +
+ " <Thrown commonElementCount=\"0\" message=\"error message\" name=\"java.lang.RuntimeException\">\n" +
+ " <ExtendedStackTrace>\n" +
+ " <ExtendedStackTraceItem\n" +
+ " class=\"logtest.Main\"\n" +
+ " method=\"main\"\n" +
+ " file=\"Main.java\"\n" +
+ " line=\"29\"\n" +
+ " exact=\"true\"\n" +
+ " location=\"classes/\"\n" +
+ " version=\"?\"/>\n" +
+ " </ExtendedStackTrace>\n" +
+ " </Thrown>\n" +
+ "</Event>";
+
+ @Before
+ public void setup() {
+ parser = new XmlLogEventParser();
+ }
+
+ @Test
+ public void testString() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(XML);
+ assertLogEvent(logEvent);
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringEmpty() throws ParseException {
+ parser.parseFrom("");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringInvalidXml() throws ParseException {
+ parser.parseFrom("foobar");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringInvalidProperty() throws ParseException {
+ parser.parseFrom("{\"foo\":\"bar\"}");
+ }
+
+ @Test
+ public void testByteArray() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(XML.getBytes(StandardCharsets.UTF_8));
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testByteArrayOffsetLength() throws ParseException {
+ byte[] bytes = ("abc" + XML + "def").getBytes(StandardCharsets.UTF_8);
+ LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testReader() throws ParseException, IOException {
+ LogEvent logEvent = parser.parseFrom(new StringReader(XML));
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testInputStream() throws ParseException, IOException {
+ LogEvent logEvent = parser.parseFrom(new ByteArrayInputStream(XML.getBytes(StandardCharsets.UTF_8)));
+ assertLogEvent(logEvent);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5bb4987/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
new file mode 100644
index 0000000..157e376
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.parser;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+
+public class YamlLogEventParserTest extends LogEventParserTest {
+
+ private YamlLogEventParser parser;
+
+ private static final String YAML = "---\n" +
+ "timeMillis: 1493121664118\n" +
+ "thread: \"main\"\n" +
+ "level: \"INFO\"\n" +
+ "loggerName: \"HelloWorld\"\n" +
+ "marker:\n" +
+ " name: \"child\"\n" +
+ " parents:\n" +
+ " - name: \"parent\"\n" +
+ " parents:\n" +
+ " - name: \"grandparent\"\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" +
+ "contextStack:\n" +
+ "- \"one\"\n" +
+ "- \"two\"\n" +
+ "endOfBatch: false\n" +
+ "loggerFqcn: \"org.apache.logging.log4j.spi.AbstractLogger\"\n" +
+ "contextMap:\n" +
+ " bar: \"BAR\"\n" +
+ " foo: \"FOO\"\n" +
+ "threadId: 1\n" +
+ "threadPriority: 5\n" +
+ "source:\n" +
+ " class: \"logtest.Main\"\n" +
+ " method: \"main\"\n" +
+ " file: \"Main.java\"\n" +
+ " line: 29";
+
+ @Before
+ public void setup() {
+ parser = new YamlLogEventParser();
+ }
+
+ @Test
+ public void testString() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(YAML);
+ assertLogEvent(logEvent);
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringEmpty() throws ParseException {
+ parser.parseFrom("");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringInvalidYaml() throws ParseException {
+ parser.parseFrom("foobar");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringInvalidProperty() throws ParseException {
+ parser.parseFrom("{\"foo\":\"bar\"}");
+ }
+
+ @Test
+ public void testByteArray() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(YAML.getBytes(StandardCharsets.UTF_8));
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testByteArrayOffsetLength() throws ParseException {
+ byte[] bytes = ("abc" + YAML + "def").getBytes(StandardCharsets.UTF_8);
+ LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testReader() throws ParseException, IOException {
+ LogEvent logEvent = parser.parseFrom(new StringReader(YAML));
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testInputStream() throws ParseException, IOException {
+ LogEvent logEvent = parser.parseFrom(new ByteArrayInputStream(YAML.getBytes(StandardCharsets.UTF_8)));
+ assertLogEvent(logEvent);
+ }
+
+}
[09/12] logging-log4j2 git commit: LOG4J2-1986 Clarify Javadoc
Posted by mi...@apache.org.
LOG4J2-1986 Clarify Javadoc
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d3b72208
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d3b72208
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d3b72208
Branch: refs/heads/master
Commit: d3b722083b8f21ea105a4f01132f08b373cb401e
Parents: dd06dbc
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Mon Jul 24 22:30:01 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Mon Jul 24 22:30:01 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/parser/LogEventParser.java | 2 +-
.../org/apache/logging/log4j/core/parser/TextLogEventParser.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3b72208/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
index 2e4991a..aaf7c30 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
@@ -29,7 +29,7 @@ public interface LogEventParser {
/**
* Parse from an InputStream, which is expected to contain exactly one log event.
*
- * @param input the input stream
+ * @param input the input stream, which will be closed
*
* @return the parsed LogEvent, never {@literal null}.
* @throws IOException if unable to read from the input
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3b72208/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
index 660ad80..34af930 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
@@ -28,7 +28,7 @@ public interface TextLogEventParser extends LogEventParser {
/**
* Parse from a Reader, which is expected to contain exactly one log event.
*
- * @param input the reader
+ * @param input the reader, which will be closed
*
* @return the parsed LogEvent, never {@literal null}.
* @throws IOException if unable to read from the Reader
[11/12] logging-log4j2 git commit: LOG4J2-1986 Fix tests and remove
support for InputStream and Reader
Posted by mi...@apache.org.
LOG4J2-1986 Fix tests and remove support for InputStream and Reader
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ab2d3262
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ab2d3262
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ab2d3262
Branch: refs/heads/master
Commit: ab2d3262c81f1b6c9ce40a916febdef82c4ea63c
Parents: b96f522
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Wed Jul 26 21:29:19 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Wed Jul 26 21:29:19 2017 +0200
----------------------------------------------------------------------
.../parser/AbstractJacksonLogEventParser.java | 37 ++++----------------
.../log4j/core/parser/LogEventParser.java | 19 ++--------
.../log4j/core/parser/TextLogEventParser.java | 16 +--------
.../core/parser/JsonLogEventParserTest.java | 29 ++++++++-------
.../core/parser/XmlLogEventParserTest.java | 24 ++++++-------
.../core/parser/YamlLogEventParserTest.java | 24 ++++++-------
6 files changed, 47 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab2d3262/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
index 8b1ca55..a1b5264 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
@@ -16,49 +16,28 @@
*/
package org.apache.logging.log4j.core.parser;
-import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
class AbstractJacksonLogEventParser implements TextLogEventParser {
- final ObjectReader objectReader;
+ private final ObjectReader objectReader;
AbstractJacksonLogEventParser(ObjectMapper objectMapper) {
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.objectReader = objectMapper.readerFor(Log4jLogEvent.class);
}
@Override
- public LogEvent parseFrom(InputStream input) throws IOException, ParseException {
- try {
- return objectReader.readValue(input);
- } catch (JsonProcessingException e) {
- throw new ParseException(e);
- }
- }
-
- @Override
- public LogEvent parseFrom(Reader input) throws IOException, ParseException {
- try {
- return objectReader.readValue(input);
- } catch (JsonProcessingException e) {
- throw new ParseException(e);
- }
- }
-
- @Override
public LogEvent parseFrom(String input) throws ParseException {
try {
return objectReader.readValue(input);
- } catch (JsonProcessingException e) {
- throw new ParseException(e);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new ParseException(e);
}
}
@@ -66,10 +45,8 @@ class AbstractJacksonLogEventParser implements TextLogEventParser {
public LogEvent parseFrom(byte[] input) throws ParseException {
try {
return objectReader.readValue(input);
- } catch (JsonProcessingException e) {
- throw new ParseException(e);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new ParseException(e);
}
}
@@ -77,10 +54,8 @@ class AbstractJacksonLogEventParser implements TextLogEventParser {
public LogEvent parseFrom(byte[] input, int offset, int length) throws ParseException {
try {
return objectReader.readValue(input, offset, length);
- } catch (JsonProcessingException e) {
- throw new ParseException(e);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new ParseException(e);
}
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab2d3262/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
index aaf7c30..6d071bd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
@@ -18,27 +18,12 @@ package org.apache.logging.log4j.core.parser;
import org.apache.logging.log4j.core.LogEvent;
-import java.io.IOException;
-import java.io.InputStream;
-
/**
* Parse the output from a layout into instances of {@link LogEvent}.
*/
public interface LogEventParser {
-
- /**
- * Parse from an InputStream, which is expected to contain exactly one log event.
- *
- * @param input the input stream, which will be closed
- *
- * @return the parsed LogEvent, never {@literal null}.
- * @throws IOException if unable to read from the input
- * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
- */
- LogEvent parseFrom(InputStream input) throws IOException, ParseException;
-
/**
- * Parse from a byte array, which is expected to contain exactly one log event.
+ * Parses a byte array, which is expected to contain exactly one log event.
*
* @param input the byte array
*
@@ -48,7 +33,7 @@ public interface LogEventParser {
LogEvent parseFrom(byte[] input) throws ParseException;
/**
- * Parse from a specified range of a byte array. The specified range is expected to contain
+ * Parses a specified range in a byte array. The specified range is expected to contain
* exactly one log event.
*
* @param input the byte array
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab2d3262/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
index 34af930..e7e366f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
@@ -18,26 +18,12 @@ package org.apache.logging.log4j.core.parser;
import org.apache.logging.log4j.core.LogEvent;
-import java.io.IOException;
-import java.io.Reader;
-
/**
* Parse the output from a text based layout into instances of {@link LogEvent}.
*/
public interface TextLogEventParser extends LogEventParser {
/**
- * Parse from a Reader, which is expected to contain exactly one log event.
- *
- * @param input the reader, which will be closed
- *
- * @return the parsed LogEvent, never {@literal null}.
- * @throws IOException if unable to read from the Reader
- * @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
- */
- LogEvent parseFrom(Reader input) throws IOException, ParseException;
-
- /**
- * Parse from a String, which is expected to contain exactly one log event.
+ * Parses a String, which is expected to contain exactly one log event.
*
* @param input the string
*
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab2d3262/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
index 5263704..ab8ea4c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
@@ -97,32 +97,35 @@ public class JsonLogEventParserTest extends LogEventParserTest {
}
@Test(expected = ParseException.class)
- public void testStringInvalidProperty() throws ParseException {
- parser.parseFrom("{\"foo\":\"bar\"}");
+ public void testStringJsonArray() throws ParseException {
+ parser.parseFrom("[]");
}
@Test
- public void testByteArray() throws ParseException {
- LogEvent logEvent = parser.parseFrom(JSON.getBytes(StandardCharsets.UTF_8));
- assertLogEvent(logEvent);
+ public void testEmptyObject() throws ParseException {
+ parser.parseFrom("{}");
+ }
+
+ @Test(expected = ParseException.class)
+ public void testStringWrongPropertyType() throws ParseException {
+ parser.parseFrom("{\"timeMillis\":\"foobar\"}");
}
@Test
- public void testByteArrayOffsetLength() throws ParseException {
- byte[] bytes = ("abc" + JSON + "def").getBytes(StandardCharsets.UTF_8);
- LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
- assertLogEvent(logEvent);
+ public void testStringIgnoreInvalidProperty() throws ParseException {
+ parser.parseFrom("{\"foo\":\"bar\"}");
}
@Test
- public void testReader() throws ParseException, IOException {
- LogEvent logEvent = parser.parseFrom(new StringReader(JSON));
+ public void testByteArray() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(JSON.getBytes(StandardCharsets.UTF_8));
assertLogEvent(logEvent);
}
@Test
- public void testInputStream() throws ParseException, IOException {
- LogEvent logEvent = parser.parseFrom(new ByteArrayInputStream(JSON.getBytes(StandardCharsets.UTF_8)));
+ public void testByteArrayOffsetLength() throws ParseException {
+ byte[] bytes = ("abc" + JSON + "def").getBytes(StandardCharsets.UTF_8);
+ LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
assertLogEvent(logEvent);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab2d3262/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
index 1d8f3c1..d24fb32 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
@@ -96,8 +96,18 @@ public class XmlLogEventParserTest extends LogEventParserTest {
parser.parseFrom("foobar");
}
+ @Test
+ public void testEmptyObject() throws ParseException {
+ parser.parseFrom("<Event></Event>");
+ }
+
@Test(expected = ParseException.class)
- public void testStringInvalidProperty() throws ParseException {
+ public void testStringWrongPropertyType() throws ParseException {
+ parser.parseFrom("<Event><timeMillis>foobar</timeMillis></Event>");
+ }
+
+ @Test
+ public void testStringIgnoreInvalidProperty() throws ParseException {
parser.parseFrom("<Event><foo>bar</foo></Event>");
}
@@ -114,16 +124,4 @@ public class XmlLogEventParserTest extends LogEventParserTest {
assertLogEvent(logEvent);
}
- @Test
- public void testReader() throws ParseException, IOException {
- LogEvent logEvent = parser.parseFrom(new StringReader(XML));
- assertLogEvent(logEvent);
- }
-
- @Test
- public void testInputStream() throws ParseException, IOException {
- LogEvent logEvent = parser.parseFrom(new ByteArrayInputStream(XML.getBytes(StandardCharsets.UTF_8)));
- assertLogEvent(logEvent);
- }
-
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab2d3262/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
index c4a7de2..2145793 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
@@ -90,8 +90,18 @@ public class YamlLogEventParserTest extends LogEventParserTest {
parser.parseFrom("foobar");
}
+ @Test
+ public void testEmptyObject() throws ParseException {
+ parser.parseFrom("---\n");
+ }
+
@Test(expected = ParseException.class)
- public void testStringInvalidProperty() throws ParseException {
+ public void testStringWrongPropertyType() throws ParseException {
+ parser.parseFrom("---\ntimeMillis: \"foobar\"\n");
+ }
+
+ @Test
+ public void testStringIgnoreInvalidProperty() throws ParseException {
parser.parseFrom("---\nfoo: \"bar\"\n");
}
@@ -108,16 +118,4 @@ public class YamlLogEventParserTest extends LogEventParserTest {
assertLogEvent(logEvent);
}
- @Test
- public void testReader() throws ParseException, IOException {
- LogEvent logEvent = parser.parseFrom(new StringReader(YAML));
- assertLogEvent(logEvent);
- }
-
- @Test
- public void testInputStream() throws ParseException, IOException {
- LogEvent logEvent = parser.parseFrom(new ByteArrayInputStream(YAML.getBytes(StandardCharsets.UTF_8)));
- assertLogEvent(logEvent);
- }
-
}
[04/12] logging-log4j2 git commit: LOG4J2-1986 Fix XML and YAML tests
Posted by mi...@apache.org.
LOG4J2-1986 Fix XML and YAML tests
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f1bb43c5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f1bb43c5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f1bb43c5
Branch: refs/heads/master
Commit: f1bb43c5579d058aee9134b3c5b164e2e5eae82e
Parents: a5bb498
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Sun Jul 23 21:53:41 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Sun Jul 23 21:53:41 2017 +0200
----------------------------------------------------------------------
.../apache/logging/log4j/core/parser/XmlLogEventParserTest.java | 2 +-
.../apache/logging/log4j/core/parser/YamlLogEventParserTest.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f1bb43c5/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
index 802b7d4..1d8f3c1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/XmlLogEventParserTest.java
@@ -98,7 +98,7 @@ public class XmlLogEventParserTest extends LogEventParserTest {
@Test(expected = ParseException.class)
public void testStringInvalidProperty() throws ParseException {
- parser.parseFrom("{\"foo\":\"bar\"}");
+ parser.parseFrom("<Event><foo>bar</foo></Event>");
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f1bb43c5/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
index 157e376..c4a7de2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/YamlLogEventParserTest.java
@@ -92,7 +92,7 @@ public class YamlLogEventParserTest extends LogEventParserTest {
@Test(expected = ParseException.class)
public void testStringInvalidProperty() throws ParseException {
- parser.parseFrom("{\"foo\":\"bar\"}");
+ parser.parseFrom("---\nfoo: \"bar\"\n");
}
@Test
[06/12] logging-log4j2 git commit: LOG4J2-1986 Add serialVersionUID
Posted by mi...@apache.org.
LOG4J2-1986 Add serialVersionUID
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7e1f7fb3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7e1f7fb3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7e1f7fb3
Branch: refs/heads/master
Commit: 7e1f7fb32047d283c954befa8c058abbad1bf8b3
Parents: db946ce
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Sun Jul 23 21:58:37 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Sun Jul 23 21:58:37 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/parser/ParseException.java | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7e1f7fb3/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
index 8f5fa54..31053d6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
@@ -20,6 +20,9 @@ package org.apache.logging.log4j.core.parser;
* Thrown when the input cannot be parsed.
*/
public class ParseException extends Exception {
+
+ private static final long serialVersionUID = -2739649998196663857L;
+
public ParseException(String message) {
super(message);
}
[08/12] logging-log4j2 git commit: LOG4J2-1986 Fix formatting
Posted by mi...@apache.org.
LOG4J2-1986 Fix formatting
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/dd06dbc1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dd06dbc1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dd06dbc1
Branch: refs/heads/master
Commit: dd06dbc16eb68ffcc03ee20ed5a377dec2f1c356
Parents: 2e1815e
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Mon Jul 24 22:29:07 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Mon Jul 24 22:29:07 2017 +0200
----------------------------------------------------------------------
.../logging/log4j/core/parser/AbstractJacksonLogEventParser.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dd06dbc1/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
index 42d8429..8b1ca55 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
@@ -13,7 +13,8 @@
* 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.parser;
+ */
+package org.apache.logging.log4j.core.parser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
[05/12] logging-log4j2 git commit: Merge branch 'master' into
LOG4J2-1986
Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1986
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/db946ce7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/db946ce7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/db946ce7
Branch: refs/heads/master
Commit: db946ce77cce33e8d722d3b32d0bb91caeb0d17b
Parents: f1bb43c 8ca5826
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Sun Jul 23 21:55:25 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Sun Jul 23 21:55:25 2017 +0200
----------------------------------------------------------------------
src/site/xdoc/manual/layouts.xml.vm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
Re: [01/12] logging-log4j2 git commit: LOG4J2-1986 Public API for
parsing the output from JsonLayout/XmlLayout/YamlLayout into a LogEvent
Posted by Gary Gregory <ga...@gmail.com>.
Great!
Gary
On Jul 26, 2017 12:58, "Mikael Ståldal" <mi...@apache.org> wrote:
> I have fixed it, see latest master branch:
>
> https://github.com/apache/logging-log4j2/blob/master/log4j-
> core/src/main/java/org/apache/logging/log4j/core/parser/Abst
> ractJacksonLogEventParser.java
>
>
> On 2017-07-26 21:44, Gary Gregory wrote:
>
>> -1 to throwing RuntimeException, again. See the LOG4J2-1986-b branch for a
>> solution.
>>
>> Gary
>>
>> On Jul 26, 2017 12:34, <mi...@apache.org> wrote:
>>
>> Repository: logging-log4j2
>>> Updated Branches:
>>> refs/heads/master b464da6b0 -> 9576bbfe2
>>>
>>>
>>> LOG4J2-1986 Public API for parsing the output from
>>> JsonLayout/XmlLayout/YamlLayout
>>> into a LogEvent
>>>
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/
>>> commit/c4814a87
>>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c
>>> 4814a87
>>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c
>>> 4814a87
>>>
>>> Branch: refs/heads/master
>>> Commit: c4814a8730eb24bdf89cf23c89b4a957b8418ba5
>>> Parents: eea873e
>>> Author: Mikael Ståldal <mi...@staldal.nu>
>>> Authored: Sat Jul 22 22:48:24 2017 +0200
>>> Committer: Mikael Ståldal <mi...@staldal.nu>
>>> Committed: Sat Jul 22 22:48:24 2017 +0200
>>>
>>> ----------------------------------------------------------------------
>>> .../parser/AbstractJacksonLogEventParser.java | 85 +++++++++++++++
>>> .../log4j/core/parser/JsonLogEventParser.java | 32 ++++++
>>> .../log4j/core/parser/LogEventParser.java | 64 ++++++++++++
>>> .../log4j/core/parser/ParseException.java | 34 ++++++
>>> .../log4j/core/parser/TextLogEventParser.java | 50 +++++++++
>>> .../log4j/core/parser/XmlLogEventParser.java | 32 ++++++
>>> .../log4j/core/parser/YamlLogEventParser.java | 33 ++++++
>>> .../logging/log4j/core/parser/package-info.java | 20 ++++
>>> .../core/parser/JsonLogEventParserTest.java | 103
>>> +++++++++++++++++++
>>> src/changes/changes.xml | 3 +
>>> 10 files changed, 456 insertions(+)
>>> ----------------------------------------------------------------------
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>>> AbstractJacksonLogEventParser.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/
>>> org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
>>> new file mode 100644
>>> index 0000000..8b00e57
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>>> AbstractJacksonLogEventParser.java
>>> @@ -0,0 +1,85 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import com.fasterxml.jackson.core.JsonProcessingException;
>>> +import com.fasterxml.jackson.databind.ObjectReader;
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>>> +import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
>>> +
>>> +import java.io.IOException;
>>> +import java.io.InputStream;
>>> +import java.io.Reader;
>>> +
>>> +class AbstractJacksonLogEventParser implements TextLogEventParser {
>>> + final ObjectReader objectReader;
>>> +
>>> + AbstractJacksonLogEventParser(ObjectReader objectReader) {
>>> + this.objectReader = objectReader;
>>> + }
>>> +
>>> + @Override
>>> + public LogEvent parseFrom(InputStream input) throws IOException,
>>> ParseException {
>>> + try {
>>> + return objectReader.readValue(input);
>>> + } catch (JsonProcessingException e) {
>>> + throw new ParseException(e);
>>> + }
>>> + }
>>> +
>>> + @Override
>>> + public LogEvent parseFrom(Reader input) throws IOException,
>>> ParseException {
>>> + try {
>>> + return objectReader.readValue(input);
>>> + } catch (JsonProcessingException e) {
>>> + throw new ParseException(e);
>>> + }
>>> + }
>>> +
>>> + @Override
>>> + public LogEvent parseFrom(String input) throws ParseException {
>>> + try {
>>> + return objectReader.readValue(input);
>>> + } catch (JsonProcessingException e) {
>>> + throw new ParseException(e);
>>> + } catch (IOException e) {
>>> + throw new RuntimeException(e);
>>> + }
>>> + }
>>> +
>>> + @Override
>>> + public LogEvent parseFrom(byte[] input) throws ParseException {
>>> + try {
>>> + return objectReader.readValue(input);
>>> + } catch (JsonProcessingException e) {
>>> + throw new ParseException(e);
>>> + } catch (IOException e) {
>>> + throw new RuntimeException(e);
>>> + }
>>> + }
>>> +
>>> + @Override
>>> + public LogEvent parseFrom(byte[] input, int offset, int length)
>>> throws ParseException {
>>> + try {
>>> + return objectReader.readValue(input, offset, length);
>>> + } catch (JsonProcessingException e) {
>>> + throw new ParseException(e);
>>> + } catch (IOException e) {
>>> + throw new RuntimeException(e);
>>> + }
>>> + }
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>>> JsonLogEventParser.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/JsonLogEventParser.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/JsonLogEventParser.java
>>> new file mode 100644
>>> index 0000000..218de0b
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/JsonLogEventParser.java
>>> @@ -0,0 +1,32 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>>> +import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
>>> +
>>> +/**
>>> + * Parse the output from JsonLayout layout into instances of {@link
>>> LogEvent}.
>>> + */
>>> +public class JsonLogEventParser extends AbstractJacksonLogEventParser {
>>> +
>>> + public JsonLogEventParser() {
>>> + super(new Log4jJsonObjectMapper().reader
>>> For(Log4jLogEvent.class)
>>> );
>>> + }
>>> +
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>>> core/parser/LogEventParser.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/LogEventParser.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/LogEventParser.java
>>> new file mode 100644
>>> index 0000000..88e84fb
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/LogEventParser.java
>>> @@ -0,0 +1,64 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +
>>> +import java.io.IOException;
>>> +import java.io.InputStream;
>>> +
>>> +/**
>>> + * Parse the output from a layout into instances of {@link LogEvent}.
>>> + */
>>> +public interface LogEventParser {
>>> +
>>> + /**
>>> + * Parse from an InputStream. The input stream may contain multiple
>>> log events.
>>> + * This method will read one log event and leave the stream open and
>>> positioned to read the
>>> + * next log event.
>>> + *
>>> + * @param input the input stream
>>> + *
>>> + * @return the parsed LogEvent, or {@literal null} of end of input
>>> is
>>> reached.
>>> + * @throws IOException if unable to read from the input
>>> + * @throws ParseException if the input is malformed and cannot be
>>> parsed as a LogEvent
>>> + */
>>> + LogEvent parseFrom(InputStream input) throws IOException,
>>> ParseException;
>>> +
>>> + /**
>>> + * Parse from a byte array, which is expected to contain exactly one
>>> log event.
>>> + *
>>> + * @param input the byte array
>>> + *
>>> + * @return the parsed LogEvent, never {@literal null}.
>>> + * @throws ParseException if the input is malformed and cannot be
>>> parsed as a LogEvent
>>> + */
>>> + LogEvent parseFrom(byte[] input) throws ParseException;
>>> +
>>> + /**
>>> + * Parse from a specified range of a byte array. The specified range
>>> is expected to contain
>>> + * exactly one log event.
>>> + *
>>> + * @param input the byte array
>>> + * @param offset the initial offset
>>> + * @param length the length
>>> + *
>>> + * @return the parsed LogEvent, never {@literal null}.
>>> + * @throws ParseException if the input is malformed and cannot be
>>> parsed as a LogEvent
>>> + */
>>> + LogEvent parseFrom(byte[] input, int offset, int length) throws
>>> ParseException;
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>>> core/parser/ParseException.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/ParseException.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/ParseException.java
>>> new file mode 100644
>>> index 0000000..8f5fa54
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/ParseException.java
>>> @@ -0,0 +1,34 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +/**
>>> + * Thrown when the input cannot be parsed.
>>> + */
>>> +public class ParseException extends Exception {
>>> + public ParseException(String message) {
>>> + super(message);
>>> + }
>>> +
>>> + public ParseException(String message, Throwable cause) {
>>> + super(message, cause);
>>> + }
>>> +
>>> + public ParseException(Throwable cause) {
>>> + super(cause);
>>> + }
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>>> TextLogEventParser.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/TextLogEventParser.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/TextLogEventParser.java
>>> new file mode 100644
>>> index 0000000..3428024
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/TextLogEventParser.java
>>> @@ -0,0 +1,50 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +
>>> +import java.io.IOException;
>>> +import java.io.Reader;
>>> +
>>> +/**
>>> + * Parse the output from a text based layout into instances of {@link
>>> LogEvent}.
>>> + */
>>> +public interface TextLogEventParser extends LogEventParser {
>>> + /**
>>> + * Parse from a Reader. The reader may contain multiple log events.
>>> + * This method will read one log event and leave the reader open and
>>> positioned to read the
>>> + * next log event.
>>> + *
>>> + * @param input the reader
>>> + *
>>> + * @return the parsed LogEvent, or {@literal null} of end of input
>>> is
>>> reached.
>>> + * @throws IOException if unable to read from the input
>>> + * @throws ParseException if the input is malformed and cannot be
>>> parsed as a LogEvent
>>> + */
>>> + LogEvent parseFrom(Reader input) throws IOException, ParseException;
>>> +
>>> + /**
>>> + * Parse from a String, which is expected to contain exactly one log
>>> event.
>>> + *
>>> + * @param input the string
>>> + *
>>> + * @return the parsed LogEvent
>>> + * @throws ParseException if the input is malformed and cannot be
>>> parsed as a LogEvent
>>> + */
>>> + LogEvent parseFrom(String input) throws ParseException;
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>>> core/parser/XmlLogEventParser.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/XmlLogEventParser.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/XmlLogEventParser.java
>>> new file mode 100644
>>> index 0000000..597e70b
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/XmlLogEventParser.java
>>> @@ -0,0 +1,32 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>>> +import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
>>> +
>>> +/**
>>> + * Parse the output from XmlLayout layout into instances of {@link
>>> LogEvent}.
>>> + */
>>> +public class XmlLogEventParser extends AbstractJacksonLogEventParser {
>>> +
>>> + public XmlLogEventParser() {
>>> + super(new Log4jXmlObjectMapper().readerF
>>> or(Log4jLogEvent.class));
>>> + }
>>> +
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>>> YamlLogEventParser.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/YamlLogEventParser.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/YamlLogEventParser.java
>>> new file mode 100644
>>> index 0000000..59b3463
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/YamlLogEventParser.java
>>> @@ -0,0 +1,33 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>>> +import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
>>> +import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
>>> +
>>> +/**
>>> + * Parse the output from YamlLayout layout into instances of {@link
>>> LogEvent}.
>>> + */
>>> +public class YamlLogEventParser extends AbstractJacksonLogEventParser {
>>> +
>>> + public YamlLogEventParser() {
>>> + super(new Log4jYamlObjectMapper().reader
>>> For(Log4jLogEvent.class)
>>> );
>>> + }
>>> +
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>>> core/parser/package-info.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/par
>>> ser/package-info.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/package-info.java
>>> new file mode 100644
>>> index 0000000..3506570
>>> --- /dev/null
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>>> parser/package-info.java
>>> @@ -0,0 +1,20 @@
>>> +/*
>>> + * 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.
>>> + */
>>> +/**
>>> + * Parsers for the output of various layouts.
>>> + */
>>> +package org.apache.logging.log4j.core.parser;
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/
>>> JsonLogEventParserTest.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/
>>> parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/
>>> org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
>>> new file mode 100644
>>> index 0000000..5684602
>>> --- /dev/null
>>> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/
>>> parser/JsonLogEventParserTest.java
>>> @@ -0,0 +1,103 @@
>>> +/*
>>> + * 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.parser;
>>> +
>>> +import org.apache.logging.log4j.core.LogEvent;
>>> +import org.junit.Before;
>>> +import org.junit.Test;
>>> +
>>> +import static org.junit.Assert.assertEquals;
>>> +import static org.junit.Assert.assertNotNull;
>>> +
>>> +public class JsonLogEventParserTest {
>>> +
>>> + private JsonLogEventParser parser;
>>> +
>>> + private static final String JSON = "{\n" +
>>> + " \"timeMillis\" : 1493121664118,\n" +
>>> + " \"thread\" : \"main\",\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" +
>>> + " \"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" +
>>> + " \"endOfBatch\" : false,\n" +
>>> + " \"loggerFqcn\" : \"org.apache.logging.log4j.spi
>>> .AbstractLogger\",\n"
>>> +
>>> + " \"contextMap\" : {\n" +
>>> + " \"bar\" : \"BAR\",\n" +
>>> + " \"foo\" : \"FOO\"\n" +
>>> + " },\n" +
>>> + " \"threadId\" : 1,\n" +
>>> + " \"threadPriority\" : 5,\n" +
>>> + " \"source\" : {\n" +
>>> + " \"class\" : \"logtest.Main\",\n" +
>>> + " \"method\" : \"main\",\n" +
>>> + " \"file\" : \"Main.java\",\n" +
>>> + " \"line\" : 29\n" +
>>> + " }\n" +
>>> + "}";
>>> +
>>> + @Before
>>> + public void setup() {
>>> + parser = new JsonLogEventParser();
>>> + }
>>> +
>>> + @Test
>>> + public void testString() throws ParseException {
>>> + LogEvent logEvent = parser.parseFrom(JSON);
>>> + assertNotNull(logEvent);
>>> + assertEquals("HelloWorld", logEvent.getLoggerName());
>>> + // TODO assert more here
>>> + }
>>> +
>>> + @Test(expected = ParseException.class)
>>> + public void testStringEmpty() throws ParseException {
>>> + parser.parseFrom("");
>>> + }
>>> +
>>> + @Test(expected = ParseException.class)
>>> + public void testStringInvalidJson() throws ParseException {
>>> + parser.parseFrom("foobar");
>>> + }
>>> +
>>> + @Test(expected = ParseException.class)
>>> + public void testStringInvalidProperty() throws ParseException {
>>> + parser.parseFrom("{\"foo\":\"bar\"}");
>>> + }
>>> +
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>>> c4814a87/src/changes/changes.xml
>>> ----------------------------------------------------------------------
>>> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
>>> index 074e31c..522f49b 100644
>>> --- a/src/changes/changes.xml
>>> +++ b/src/changes/changes.xml
>>> @@ -31,6 +31,9 @@
>>> - "remove" - Removed
>>> -->
>>> <release version="2.9.0" date="2017-MM-DD" description="GA Release
>>> 2.9.0">
>>> + <action issue="LOG4J2-1986" dev="mikes" type="add">
>>> + Public API for parsing the output from
>>> JsonLayout/XmlLayout/YamlLayout
>>> into a LogEvent.
>>> + </action>
>>> <action issue="LOG4J2-1984" dev="rgoers" type="update">
>>> Allow maxLength of StructuredData to be specified by the user.
>>> </action>
>>>
>>>
>>>
>>
>
Re: [01/12] logging-log4j2 git commit: LOG4J2-1986 Public API for
parsing the output from JsonLayout/XmlLayout/YamlLayout into a LogEvent
Posted by Mikael Ståldal <mi...@apache.org>.
I have fixed it, see latest master branch:
https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
On 2017-07-26 21:44, Gary Gregory wrote:
> -1 to throwing RuntimeException, again. See the LOG4J2-1986-b branch for a
> solution.
>
> Gary
>
> On Jul 26, 2017 12:34, <mi...@apache.org> wrote:
>
>> Repository: logging-log4j2
>> Updated Branches:
>> refs/heads/master b464da6b0 -> 9576bbfe2
>>
>>
>> LOG4J2-1986 Public API for parsing the output from JsonLayout/XmlLayout/YamlLayout
>> into a LogEvent
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/
>> commit/c4814a87
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c4814a87
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c4814a87
>>
>> Branch: refs/heads/master
>> Commit: c4814a8730eb24bdf89cf23c89b4a957b8418ba5
>> Parents: eea873e
>> Author: Mikael Ståldal <mi...@staldal.nu>
>> Authored: Sat Jul 22 22:48:24 2017 +0200
>> Committer: Mikael Ståldal <mi...@staldal.nu>
>> Committed: Sat Jul 22 22:48:24 2017 +0200
>>
>> ----------------------------------------------------------------------
>> .../parser/AbstractJacksonLogEventParser.java | 85 +++++++++++++++
>> .../log4j/core/parser/JsonLogEventParser.java | 32 ++++++
>> .../log4j/core/parser/LogEventParser.java | 64 ++++++++++++
>> .../log4j/core/parser/ParseException.java | 34 ++++++
>> .../log4j/core/parser/TextLogEventParser.java | 50 +++++++++
>> .../log4j/core/parser/XmlLogEventParser.java | 32 ++++++
>> .../log4j/core/parser/YamlLogEventParser.java | 33 ++++++
>> .../logging/log4j/core/parser/package-info.java | 20 ++++
>> .../core/parser/JsonLogEventParserTest.java | 103 +++++++++++++++++++
>> src/changes/changes.xml | 3 +
>> 10 files changed, 456 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>> AbstractJacksonLogEventParser.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/
>> org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
>> new file mode 100644
>> index 0000000..8b00e57
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>> AbstractJacksonLogEventParser.java
>> @@ -0,0 +1,85 @@
>> +/*
>> + * 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.parser;
>> +
>> +import com.fasterxml.jackson.core.JsonProcessingException;
>> +import com.fasterxml.jackson.databind.ObjectReader;
>> +import org.apache.logging.log4j.core.LogEvent;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
>> +
>> +import java.io.IOException;
>> +import java.io.InputStream;
>> +import java.io.Reader;
>> +
>> +class AbstractJacksonLogEventParser implements TextLogEventParser {
>> + final ObjectReader objectReader;
>> +
>> + AbstractJacksonLogEventParser(ObjectReader objectReader) {
>> + this.objectReader = objectReader;
>> + }
>> +
>> + @Override
>> + public LogEvent parseFrom(InputStream input) throws IOException,
>> ParseException {
>> + try {
>> + return objectReader.readValue(input);
>> + } catch (JsonProcessingException e) {
>> + throw new ParseException(e);
>> + }
>> + }
>> +
>> + @Override
>> + public LogEvent parseFrom(Reader input) throws IOException,
>> ParseException {
>> + try {
>> + return objectReader.readValue(input);
>> + } catch (JsonProcessingException e) {
>> + throw new ParseException(e);
>> + }
>> + }
>> +
>> + @Override
>> + public LogEvent parseFrom(String input) throws ParseException {
>> + try {
>> + return objectReader.readValue(input);
>> + } catch (JsonProcessingException e) {
>> + throw new ParseException(e);
>> + } catch (IOException e) {
>> + throw new RuntimeException(e);
>> + }
>> + }
>> +
>> + @Override
>> + public LogEvent parseFrom(byte[] input) throws ParseException {
>> + try {
>> + return objectReader.readValue(input);
>> + } catch (JsonProcessingException e) {
>> + throw new ParseException(e);
>> + } catch (IOException e) {
>> + throw new RuntimeException(e);
>> + }
>> + }
>> +
>> + @Override
>> + public LogEvent parseFrom(byte[] input, int offset, int length)
>> throws ParseException {
>> + try {
>> + return objectReader.readValue(input, offset, length);
>> + } catch (JsonProcessingException e) {
>> + throw new ParseException(e);
>> + } catch (IOException e) {
>> + throw new RuntimeException(e);
>> + }
>> + }
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>> JsonLogEventParser.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/JsonLogEventParser.java
>> new file mode 100644
>> index 0000000..218de0b
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/JsonLogEventParser.java
>> @@ -0,0 +1,32 @@
>> +/*
>> + * 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.parser;
>> +
>> +import org.apache.logging.log4j.core.LogEvent;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
>> +
>> +/**
>> + * Parse the output from JsonLayout layout into instances of {@link
>> LogEvent}.
>> + */
>> +public class JsonLogEventParser extends AbstractJacksonLogEventParser {
>> +
>> + public JsonLogEventParser() {
>> + super(new Log4jJsonObjectMapper().readerFor(Log4jLogEvent.class)
>> );
>> + }
>> +
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>> core/parser/LogEventParser.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/LogEventParser.java
>> new file mode 100644
>> index 0000000..88e84fb
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/LogEventParser.java
>> @@ -0,0 +1,64 @@
>> +/*
>> + * 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.parser;
>> +
>> +import org.apache.logging.log4j.core.LogEvent;
>> +
>> +import java.io.IOException;
>> +import java.io.InputStream;
>> +
>> +/**
>> + * Parse the output from a layout into instances of {@link LogEvent}.
>> + */
>> +public interface LogEventParser {
>> +
>> + /**
>> + * Parse from an InputStream. The input stream may contain multiple
>> log events.
>> + * This method will read one log event and leave the stream open and
>> positioned to read the
>> + * next log event.
>> + *
>> + * @param input the input stream
>> + *
>> + * @return the parsed LogEvent, or {@literal null} of end of input is
>> reached.
>> + * @throws IOException if unable to read from the input
>> + * @throws ParseException if the input is malformed and cannot be
>> parsed as a LogEvent
>> + */
>> + LogEvent parseFrom(InputStream input) throws IOException,
>> ParseException;
>> +
>> + /**
>> + * Parse from a byte array, which is expected to contain exactly one
>> log event.
>> + *
>> + * @param input the byte array
>> + *
>> + * @return the parsed LogEvent, never {@literal null}.
>> + * @throws ParseException if the input is malformed and cannot be
>> parsed as a LogEvent
>> + */
>> + LogEvent parseFrom(byte[] input) throws ParseException;
>> +
>> + /**
>> + * Parse from a specified range of a byte array. The specified range
>> is expected to contain
>> + * exactly one log event.
>> + *
>> + * @param input the byte array
>> + * @param offset the initial offset
>> + * @param length the length
>> + *
>> + * @return the parsed LogEvent, never {@literal null}.
>> + * @throws ParseException if the input is malformed and cannot be
>> parsed as a LogEvent
>> + */
>> + LogEvent parseFrom(byte[] input, int offset, int length) throws
>> ParseException;
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>> core/parser/ParseException.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/ParseException.java
>> new file mode 100644
>> index 0000000..8f5fa54
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/ParseException.java
>> @@ -0,0 +1,34 @@
>> +/*
>> + * 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.parser;
>> +
>> +/**
>> + * Thrown when the input cannot be parsed.
>> + */
>> +public class ParseException extends Exception {
>> + public ParseException(String message) {
>> + super(message);
>> + }
>> +
>> + public ParseException(String message, Throwable cause) {
>> + super(message, cause);
>> + }
>> +
>> + public ParseException(Throwable cause) {
>> + super(cause);
>> + }
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>> TextLogEventParser.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/TextLogEventParser.java
>> new file mode 100644
>> index 0000000..3428024
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/TextLogEventParser.java
>> @@ -0,0 +1,50 @@
>> +/*
>> + * 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.parser;
>> +
>> +import org.apache.logging.log4j.core.LogEvent;
>> +
>> +import java.io.IOException;
>> +import java.io.Reader;
>> +
>> +/**
>> + * Parse the output from a text based layout into instances of {@link
>> LogEvent}.
>> + */
>> +public interface TextLogEventParser extends LogEventParser {
>> + /**
>> + * Parse from a Reader. The reader may contain multiple log events.
>> + * This method will read one log event and leave the reader open and
>> positioned to read the
>> + * next log event.
>> + *
>> + * @param input the reader
>> + *
>> + * @return the parsed LogEvent, or {@literal null} of end of input is
>> reached.
>> + * @throws IOException if unable to read from the input
>> + * @throws ParseException if the input is malformed and cannot be
>> parsed as a LogEvent
>> + */
>> + LogEvent parseFrom(Reader input) throws IOException, ParseException;
>> +
>> + /**
>> + * Parse from a String, which is expected to contain exactly one log
>> event.
>> + *
>> + * @param input the string
>> + *
>> + * @return the parsed LogEvent
>> + * @throws ParseException if the input is malformed and cannot be
>> parsed as a LogEvent
>> + */
>> + LogEvent parseFrom(String input) throws ParseException;
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>> core/parser/XmlLogEventParser.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/XmlLogEventParser.java
>> new file mode 100644
>> index 0000000..597e70b
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/XmlLogEventParser.java
>> @@ -0,0 +1,32 @@
>> +/*
>> + * 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.parser;
>> +
>> +import org.apache.logging.log4j.core.LogEvent;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
>> +
>> +/**
>> + * Parse the output from XmlLayout layout into instances of {@link
>> LogEvent}.
>> + */
>> +public class XmlLogEventParser extends AbstractJacksonLogEventParser {
>> +
>> + public XmlLogEventParser() {
>> + super(new Log4jXmlObjectMapper().readerFor(Log4jLogEvent.class));
>> + }
>> +
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
>> YamlLogEventParser.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/YamlLogEventParser.java
>> new file mode 100644
>> index 0000000..59b3463
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/YamlLogEventParser.java
>> @@ -0,0 +1,33 @@
>> +/*
>> + * 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.parser;
>> +
>> +import org.apache.logging.log4j.core.LogEvent;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
>> +import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
>> +
>> +/**
>> + * Parse the output from YamlLayout layout into instances of {@link
>> LogEvent}.
>> + */
>> +public class YamlLogEventParser extends AbstractJacksonLogEventParser {
>> +
>> + public YamlLogEventParser() {
>> + super(new Log4jYamlObjectMapper().readerFor(Log4jLogEvent.class)
>> );
>> + }
>> +
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
>> core/parser/package-info.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/package-info.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/package-info.java
>> new file mode 100644
>> index 0000000..3506570
>> --- /dev/null
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
>> parser/package-info.java
>> @@ -0,0 +1,20 @@
>> +/*
>> + * 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.
>> + */
>> +/**
>> + * Parsers for the output of various layouts.
>> + */
>> +package org.apache.logging.log4j.core.parser;
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/
>> JsonLogEventParserTest.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/
>> parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/
>> org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
>> new file mode 100644
>> index 0000000..5684602
>> --- /dev/null
>> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/
>> parser/JsonLogEventParserTest.java
>> @@ -0,0 +1,103 @@
>> +/*
>> + * 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.parser;
>> +
>> +import org.apache.logging.log4j.core.LogEvent;
>> +import org.junit.Before;
>> +import org.junit.Test;
>> +
>> +import static org.junit.Assert.assertEquals;
>> +import static org.junit.Assert.assertNotNull;
>> +
>> +public class JsonLogEventParserTest {
>> +
>> + private JsonLogEventParser parser;
>> +
>> + private static final String JSON = "{\n" +
>> + " \"timeMillis\" : 1493121664118,\n" +
>> + " \"thread\" : \"main\",\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" +
>> + " \"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" +
>> + " \"endOfBatch\" : false,\n" +
>> + " \"loggerFqcn\" : \"org.apache.logging.log4j.spi.AbstractLogger\",\n"
>> +
>> + " \"contextMap\" : {\n" +
>> + " \"bar\" : \"BAR\",\n" +
>> + " \"foo\" : \"FOO\"\n" +
>> + " },\n" +
>> + " \"threadId\" : 1,\n" +
>> + " \"threadPriority\" : 5,\n" +
>> + " \"source\" : {\n" +
>> + " \"class\" : \"logtest.Main\",\n" +
>> + " \"method\" : \"main\",\n" +
>> + " \"file\" : \"Main.java\",\n" +
>> + " \"line\" : 29\n" +
>> + " }\n" +
>> + "}";
>> +
>> + @Before
>> + public void setup() {
>> + parser = new JsonLogEventParser();
>> + }
>> +
>> + @Test
>> + public void testString() throws ParseException {
>> + LogEvent logEvent = parser.parseFrom(JSON);
>> + assertNotNull(logEvent);
>> + assertEquals("HelloWorld", logEvent.getLoggerName());
>> + // TODO assert more here
>> + }
>> +
>> + @Test(expected = ParseException.class)
>> + public void testStringEmpty() throws ParseException {
>> + parser.parseFrom("");
>> + }
>> +
>> + @Test(expected = ParseException.class)
>> + public void testStringInvalidJson() throws ParseException {
>> + parser.parseFrom("foobar");
>> + }
>> +
>> + @Test(expected = ParseException.class)
>> + public void testStringInvalidProperty() throws ParseException {
>> + parser.parseFrom("{\"foo\":\"bar\"}");
>> + }
>> +
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
>> c4814a87/src/changes/changes.xml
>> ----------------------------------------------------------------------
>> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
>> index 074e31c..522f49b 100644
>> --- a/src/changes/changes.xml
>> +++ b/src/changes/changes.xml
>> @@ -31,6 +31,9 @@
>> - "remove" - Removed
>> -->
>> <release version="2.9.0" date="2017-MM-DD" description="GA Release
>> 2.9.0">
>> + <action issue="LOG4J2-1986" dev="mikes" type="add">
>> + Public API for parsing the output from JsonLayout/XmlLayout/YamlLayout
>> into a LogEvent.
>> + </action>
>> <action issue="LOG4J2-1984" dev="rgoers" type="update">
>> Allow maxLength of StructuredData to be specified by the user.
>> </action>
>>
>>
>
Re: [01/12] logging-log4j2 git commit: LOG4J2-1986 Public API for
parsing the output from JsonLayout/XmlLayout/YamlLayout into a LogEvent
Posted by Gary Gregory <ga...@gmail.com>.
-1 to throwing RuntimeException, again. See the LOG4J2-1986-b branch for a
solution.
Gary
On Jul 26, 2017 12:34, <mi...@apache.org> wrote:
> Repository: logging-log4j2
> Updated Branches:
> refs/heads/master b464da6b0 -> 9576bbfe2
>
>
> LOG4J2-1986 Public API for parsing the output from JsonLayout/XmlLayout/YamlLayout
> into a LogEvent
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/
> commit/c4814a87
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c4814a87
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c4814a87
>
> Branch: refs/heads/master
> Commit: c4814a8730eb24bdf89cf23c89b4a957b8418ba5
> Parents: eea873e
> Author: Mikael Ståldal <mi...@staldal.nu>
> Authored: Sat Jul 22 22:48:24 2017 +0200
> Committer: Mikael Ståldal <mi...@staldal.nu>
> Committed: Sat Jul 22 22:48:24 2017 +0200
>
> ----------------------------------------------------------------------
> .../parser/AbstractJacksonLogEventParser.java | 85 +++++++++++++++
> .../log4j/core/parser/JsonLogEventParser.java | 32 ++++++
> .../log4j/core/parser/LogEventParser.java | 64 ++++++++++++
> .../log4j/core/parser/ParseException.java | 34 ++++++
> .../log4j/core/parser/TextLogEventParser.java | 50 +++++++++
> .../log4j/core/parser/XmlLogEventParser.java | 32 ++++++
> .../log4j/core/parser/YamlLogEventParser.java | 33 ++++++
> .../logging/log4j/core/parser/package-info.java | 20 ++++
> .../core/parser/JsonLogEventParserTest.java | 103 +++++++++++++++++++
> src/changes/changes.xml | 3 +
> 10 files changed, 456 insertions(+)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
> AbstractJacksonLogEventParser.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/
> org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
> new file mode 100644
> index 0000000..8b00e57
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
> AbstractJacksonLogEventParser.java
> @@ -0,0 +1,85 @@
> +/*
> + * 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.parser;
> +
> +import com.fasterxml.jackson.core.JsonProcessingException;
> +import com.fasterxml.jackson.databind.ObjectReader;
> +import org.apache.logging.log4j.core.LogEvent;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.io.Reader;
> +
> +class AbstractJacksonLogEventParser implements TextLogEventParser {
> + final ObjectReader objectReader;
> +
> + AbstractJacksonLogEventParser(ObjectReader objectReader) {
> + this.objectReader = objectReader;
> + }
> +
> + @Override
> + public LogEvent parseFrom(InputStream input) throws IOException,
> ParseException {
> + try {
> + return objectReader.readValue(input);
> + } catch (JsonProcessingException e) {
> + throw new ParseException(e);
> + }
> + }
> +
> + @Override
> + public LogEvent parseFrom(Reader input) throws IOException,
> ParseException {
> + try {
> + return objectReader.readValue(input);
> + } catch (JsonProcessingException e) {
> + throw new ParseException(e);
> + }
> + }
> +
> + @Override
> + public LogEvent parseFrom(String input) throws ParseException {
> + try {
> + return objectReader.readValue(input);
> + } catch (JsonProcessingException e) {
> + throw new ParseException(e);
> + } catch (IOException e) {
> + throw new RuntimeException(e);
> + }
> + }
> +
> + @Override
> + public LogEvent parseFrom(byte[] input) throws ParseException {
> + try {
> + return objectReader.readValue(input);
> + } catch (JsonProcessingException e) {
> + throw new ParseException(e);
> + } catch (IOException e) {
> + throw new RuntimeException(e);
> + }
> + }
> +
> + @Override
> + public LogEvent parseFrom(byte[] input, int offset, int length)
> throws ParseException {
> + try {
> + return objectReader.readValue(input, offset, length);
> + } catch (JsonProcessingException e) {
> + throw new ParseException(e);
> + } catch (IOException e) {
> + throw new RuntimeException(e);
> + }
> + }
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
> JsonLogEventParser.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/JsonLogEventParser.java
> new file mode 100644
> index 0000000..218de0b
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/JsonLogEventParser.java
> @@ -0,0 +1,32 @@
> +/*
> + * 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.parser;
> +
> +import org.apache.logging.log4j.core.LogEvent;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
> +
> +/**
> + * Parse the output from JsonLayout layout into instances of {@link
> LogEvent}.
> + */
> +public class JsonLogEventParser extends AbstractJacksonLogEventParser {
> +
> + public JsonLogEventParser() {
> + super(new Log4jJsonObjectMapper().readerFor(Log4jLogEvent.class)
> );
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
> core/parser/LogEventParser.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/LogEventParser.java
> new file mode 100644
> index 0000000..88e84fb
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/LogEventParser.java
> @@ -0,0 +1,64 @@
> +/*
> + * 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.parser;
> +
> +import org.apache.logging.log4j.core.LogEvent;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +
> +/**
> + * Parse the output from a layout into instances of {@link LogEvent}.
> + */
> +public interface LogEventParser {
> +
> + /**
> + * Parse from an InputStream. The input stream may contain multiple
> log events.
> + * This method will read one log event and leave the stream open and
> positioned to read the
> + * next log event.
> + *
> + * @param input the input stream
> + *
> + * @return the parsed LogEvent, or {@literal null} of end of input is
> reached.
> + * @throws IOException if unable to read from the input
> + * @throws ParseException if the input is malformed and cannot be
> parsed as a LogEvent
> + */
> + LogEvent parseFrom(InputStream input) throws IOException,
> ParseException;
> +
> + /**
> + * Parse from a byte array, which is expected to contain exactly one
> log event.
> + *
> + * @param input the byte array
> + *
> + * @return the parsed LogEvent, never {@literal null}.
> + * @throws ParseException if the input is malformed and cannot be
> parsed as a LogEvent
> + */
> + LogEvent parseFrom(byte[] input) throws ParseException;
> +
> + /**
> + * Parse from a specified range of a byte array. The specified range
> is expected to contain
> + * exactly one log event.
> + *
> + * @param input the byte array
> + * @param offset the initial offset
> + * @param length the length
> + *
> + * @return the parsed LogEvent, never {@literal null}.
> + * @throws ParseException if the input is malformed and cannot be
> parsed as a LogEvent
> + */
> + LogEvent parseFrom(byte[] input, int offset, int length) throws
> ParseException;
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
> core/parser/ParseException.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/ParseException.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/ParseException.java
> new file mode 100644
> index 0000000..8f5fa54
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/ParseException.java
> @@ -0,0 +1,34 @@
> +/*
> + * 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.parser;
> +
> +/**
> + * Thrown when the input cannot be parsed.
> + */
> +public class ParseException extends Exception {
> + public ParseException(String message) {
> + super(message);
> + }
> +
> + public ParseException(String message, Throwable cause) {
> + super(message, cause);
> + }
> +
> + public ParseException(Throwable cause) {
> + super(cause);
> + }
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
> TextLogEventParser.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/TextLogEventParser.java
> new file mode 100644
> index 0000000..3428024
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/TextLogEventParser.java
> @@ -0,0 +1,50 @@
> +/*
> + * 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.parser;
> +
> +import org.apache.logging.log4j.core.LogEvent;
> +
> +import java.io.IOException;
> +import java.io.Reader;
> +
> +/**
> + * Parse the output from a text based layout into instances of {@link
> LogEvent}.
> + */
> +public interface TextLogEventParser extends LogEventParser {
> + /**
> + * Parse from a Reader. The reader may contain multiple log events.
> + * This method will read one log event and leave the reader open and
> positioned to read the
> + * next log event.
> + *
> + * @param input the reader
> + *
> + * @return the parsed LogEvent, or {@literal null} of end of input is
> reached.
> + * @throws IOException if unable to read from the input
> + * @throws ParseException if the input is malformed and cannot be
> parsed as a LogEvent
> + */
> + LogEvent parseFrom(Reader input) throws IOException, ParseException;
> +
> + /**
> + * Parse from a String, which is expected to contain exactly one log
> event.
> + *
> + * @param input the string
> + *
> + * @return the parsed LogEvent
> + * @throws ParseException if the input is malformed and cannot be
> parsed as a LogEvent
> + */
> + LogEvent parseFrom(String input) throws ParseException;
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
> core/parser/XmlLogEventParser.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/XmlLogEventParser.java
> new file mode 100644
> index 0000000..597e70b
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/XmlLogEventParser.java
> @@ -0,0 +1,32 @@
> +/*
> + * 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.parser;
> +
> +import org.apache.logging.log4j.core.LogEvent;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
> +
> +/**
> + * Parse the output from XmlLayout layout into instances of {@link
> LogEvent}.
> + */
> +public class XmlLogEventParser extends AbstractJacksonLogEventParser {
> +
> + public XmlLogEventParser() {
> + super(new Log4jXmlObjectMapper().readerFor(Log4jLogEvent.class));
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/
> YamlLogEventParser.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/YamlLogEventParser.java
> new file mode 100644
> index 0000000..59b3463
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/YamlLogEventParser.java
> @@ -0,0 +1,33 @@
> +/*
> + * 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.parser;
> +
> +import org.apache.logging.log4j.core.LogEvent;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
> +import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
> +
> +/**
> + * Parse the output from YamlLayout layout into instances of {@link
> LogEvent}.
> + */
> +public class YamlLogEventParser extends AbstractJacksonLogEventParser {
> +
> + public YamlLogEventParser() {
> + super(new Log4jYamlObjectMapper().readerFor(Log4jLogEvent.class)
> );
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/main/java/org/apache/logging/log4j/
> core/parser/package-info.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/package-info.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/package-info.java
> new file mode 100644
> index 0000000..3506570
> --- /dev/null
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> parser/package-info.java
> @@ -0,0 +1,20 @@
> +/*
> + * 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.
> + */
> +/**
> + * Parsers for the output of various layouts.
> + */
> +package org.apache.logging.log4j.core.parser;
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/
> JsonLogEventParserTest.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/
> parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/
> org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
> new file mode 100644
> index 0000000..5684602
> --- /dev/null
> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/
> parser/JsonLogEventParserTest.java
> @@ -0,0 +1,103 @@
> +/*
> + * 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.parser;
> +
> +import org.apache.logging.log4j.core.LogEvent;
> +import org.junit.Before;
> +import org.junit.Test;
> +
> +import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertNotNull;
> +
> +public class JsonLogEventParserTest {
> +
> + private JsonLogEventParser parser;
> +
> + private static final String JSON = "{\n" +
> + " \"timeMillis\" : 1493121664118,\n" +
> + " \"thread\" : \"main\",\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" +
> + " \"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" +
> + " \"endOfBatch\" : false,\n" +
> + " \"loggerFqcn\" : \"org.apache.logging.log4j.spi.AbstractLogger\",\n"
> +
> + " \"contextMap\" : {\n" +
> + " \"bar\" : \"BAR\",\n" +
> + " \"foo\" : \"FOO\"\n" +
> + " },\n" +
> + " \"threadId\" : 1,\n" +
> + " \"threadPriority\" : 5,\n" +
> + " \"source\" : {\n" +
> + " \"class\" : \"logtest.Main\",\n" +
> + " \"method\" : \"main\",\n" +
> + " \"file\" : \"Main.java\",\n" +
> + " \"line\" : 29\n" +
> + " }\n" +
> + "}";
> +
> + @Before
> + public void setup() {
> + parser = new JsonLogEventParser();
> + }
> +
> + @Test
> + public void testString() throws ParseException {
> + LogEvent logEvent = parser.parseFrom(JSON);
> + assertNotNull(logEvent);
> + assertEquals("HelloWorld", logEvent.getLoggerName());
> + // TODO assert more here
> + }
> +
> + @Test(expected = ParseException.class)
> + public void testStringEmpty() throws ParseException {
> + parser.parseFrom("");
> + }
> +
> + @Test(expected = ParseException.class)
> + public void testStringInvalidJson() throws ParseException {
> + parser.parseFrom("foobar");
> + }
> +
> + @Test(expected = ParseException.class)
> + public void testStringInvalidProperty() throws ParseException {
> + parser.parseFrom("{\"foo\":\"bar\"}");
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> c4814a87/src/changes/changes.xml
> ----------------------------------------------------------------------
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index 074e31c..522f49b 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -31,6 +31,9 @@
> - "remove" - Removed
> -->
> <release version="2.9.0" date="2017-MM-DD" description="GA Release
> 2.9.0">
> + <action issue="LOG4J2-1986" dev="mikes" type="add">
> + Public API for parsing the output from JsonLayout/XmlLayout/YamlLayout
> into a LogEvent.
> + </action>
> <action issue="LOG4J2-1984" dev="rgoers" type="update">
> Allow maxLength of StructuredData to be specified by the user.
> </action>
>
>
[02/12] logging-log4j2 git commit: LOG4J2-1986 More extensive unit
test
Posted by mi...@apache.org.
LOG4J2-1986 More extensive unit test
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/72d0d12a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/72d0d12a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/72d0d12a
Branch: refs/heads/master
Commit: 72d0d12a77f66228ed12f21f9965b3e408271723
Parents: c4814a8
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Sun Jul 23 21:13:59 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Sun Jul 23 21:13:59 2017 +0200
----------------------------------------------------------------------
.../core/parser/JsonLogEventParserTest.java | 75 +++++++++++++++++---
1 file changed, 67 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/72d0d12a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
index 5684602..f4efd91 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/parser/JsonLogEventParserTest.java
@@ -16,12 +16,22 @@
*/
package org.apache.logging.log4j.core.parser;
+import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
public class JsonLogEventParserTest {
@@ -30,6 +40,8 @@ public class JsonLogEventParserTest {
private static final String JSON = "{\n" +
" \"timeMillis\" : 1493121664118,\n" +
" \"thread\" : \"main\",\n" +
+ " \"threadId\" : 1,\n" +
+ " \"threadPriority\" : 5,\n" +
" \"level\" : \"INFO\",\n" +
" \"loggerName\" : \"HelloWorld\",\n" +
" \"marker\" : {\n" +
@@ -44,6 +56,7 @@ public class JsonLogEventParserTest {
" \"message\" : \"Hello, world!\",\n" +
" \"thrown\" : {\n" +
" \"commonElementCount\" : 0,\n" +
+ " \"message\" : \"error message\",\n" +
" \"name\" : \"java.lang.RuntimeException\",\n" +
" \"extendedStackTrace\" : [ {\n" +
" \"class\" : \"logtest.Main\",\n" +
@@ -56,14 +69,12 @@ public class JsonLogEventParserTest {
" } ]\n" +
" },\n" +
" \"contextStack\" : [ \"one\", \"two\" ],\n" +
- " \"endOfBatch\" : false,\n" +
" \"loggerFqcn\" : \"org.apache.logging.log4j.spi.AbstractLogger\",\n" +
+ " \"endOfBatch\" : false,\n" +
" \"contextMap\" : {\n" +
" \"bar\" : \"BAR\",\n" +
" \"foo\" : \"FOO\"\n" +
" },\n" +
- " \"threadId\" : 1,\n" +
- " \"threadPriority\" : 5,\n" +
" \"source\" : {\n" +
" \"class\" : \"logtest.Main\",\n" +
" \"method\" : \"main\",\n" +
@@ -80,9 +91,7 @@ public class JsonLogEventParserTest {
@Test
public void testString() throws ParseException {
LogEvent logEvent = parser.parseFrom(JSON);
- assertNotNull(logEvent);
- assertEquals("HelloWorld", logEvent.getLoggerName());
- // TODO assert more here
+ assertLogEvent(logEvent);
}
@Test(expected = ParseException.class)
@@ -100,4 +109,54 @@ public class JsonLogEventParserTest {
parser.parseFrom("{\"foo\":\"bar\"}");
}
+ @Test
+ public void testByteArray() throws ParseException {
+ LogEvent logEvent = parser.parseFrom(JSON.getBytes(StandardCharsets.UTF_8));
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testByteArrayOffsetLength() throws ParseException {
+ byte[] bytes = ("abc" + JSON + "def").getBytes(StandardCharsets.UTF_8);
+ LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testReader() throws ParseException, IOException {
+ LogEvent logEvent = parser.parseFrom(new StringReader(JSON));
+ assertLogEvent(logEvent);
+ }
+
+ @Test
+ public void testInputStream() throws ParseException, IOException {
+ LogEvent logEvent = parser.parseFrom(new ByteArrayInputStream(JSON.getBytes(StandardCharsets.UTF_8)));
+ assertLogEvent(logEvent);
+ }
+
+ private void assertLogEvent(LogEvent logEvent) {
+ assertThat(logEvent, is(notNullValue()));
+ assertThat(logEvent.getTimeMillis(), equalTo(1493121664118L));
+ assertThat(logEvent.getThreadName(), equalTo("main"));
+ assertThat(logEvent.getThreadId(), equalTo(1L));
+ assertThat(logEvent.getThreadPriority(), equalTo(5));
+ assertThat(logEvent.getLevel(), equalTo(Level.INFO));
+ assertThat(logEvent.getLoggerName(), equalTo("HelloWorld"));
+ assertThat(logEvent.getMarker().getName(), equalTo("child"));
+ assertThat(logEvent.getMarker().getParents()[0].getName(), equalTo("parent"));
+ assertThat(logEvent.getMarker().getParents()[0].getParents()[0].getName(),
+ equalTo("grandparent"));
+ assertThat(logEvent.getMessage().getFormattedMessage(), equalTo("Hello, world!"));
+ assertThat(logEvent.getThrown(), is(nullValue()));
+ assertThat(logEvent.getThrownProxy().getMessage(), equalTo("error message"));
+ assertThat(logEvent.getThrownProxy().getName(), equalTo("java.lang.RuntimeException"));
+ assertThat(logEvent.getThrownProxy().getExtendedStackTrace()[0].getClassName(),
+ equalTo("logtest.Main"));
+ assertThat(logEvent.getLoggerFqcn(), equalTo("org.apache.logging.log4j.spi.AbstractLogger"));
+ assertThat(logEvent.getContextStack().asList(), equalTo(Arrays.asList("one", "two")));
+ assertThat((String) logEvent.getContextData().getValue("foo"), equalTo("FOO"));
+ assertThat((String) logEvent.getContextData().getValue("bar"), equalTo("BAR"));
+ assertThat(logEvent.getSource().getClassName(), equalTo("logtest.Main"));
+ }
+
}
[07/12] logging-log4j2 git commit: LOG4J2-1986 Refactor and clarify
Javadoc
Posted by mi...@apache.org.
LOG4J2-1986 Refactor and clarify Javadoc
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2e1815eb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2e1815eb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2e1815eb
Branch: refs/heads/master
Commit: 2e1815eb4cb9f98b78d7f8c06abed53511466d95
Parents: 7e1f7fb
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Mon Jul 24 22:24:15 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Mon Jul 24 22:24:15 2017 +0200
----------------------------------------------------------------------
.../log4j/core/parser/AbstractJacksonLogEventParser.java | 6 +++---
.../logging/log4j/core/parser/JsonLogEventParser.java | 2 +-
.../apache/logging/log4j/core/parser/LogEventParser.java | 6 ++----
.../logging/log4j/core/parser/TextLogEventParser.java | 10 ++++------
.../logging/log4j/core/parser/XmlLogEventParser.java | 2 +-
.../logging/log4j/core/parser/YamlLogEventParser.java | 2 +-
6 files changed, 12 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2e1815eb/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
index 8b00e57..42d8429 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/AbstractJacksonLogEventParser.java
@@ -16,10 +16,10 @@
*/package org.apache.logging.log4j.core.parser;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
import java.io.IOException;
import java.io.InputStream;
@@ -28,8 +28,8 @@ import java.io.Reader;
class AbstractJacksonLogEventParser implements TextLogEventParser {
final ObjectReader objectReader;
- AbstractJacksonLogEventParser(ObjectReader objectReader) {
- this.objectReader = objectReader;
+ AbstractJacksonLogEventParser(ObjectMapper objectMapper) {
+ this.objectReader = objectMapper.readerFor(Log4jLogEvent.class);
}
@Override
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2e1815eb/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
index 218de0b..68d8ea8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/JsonLogEventParser.java
@@ -26,7 +26,7 @@ import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
public class JsonLogEventParser extends AbstractJacksonLogEventParser {
public JsonLogEventParser() {
- super(new Log4jJsonObjectMapper().readerFor(Log4jLogEvent.class));
+ super(new Log4jJsonObjectMapper());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2e1815eb/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
index 88e84fb..2e4991a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/LogEventParser.java
@@ -27,13 +27,11 @@ import java.io.InputStream;
public interface LogEventParser {
/**
- * Parse from an InputStream. The input stream may contain multiple log events.
- * This method will read one log event and leave the stream open and positioned to read the
- * next log event.
+ * Parse from an InputStream, which is expected to contain exactly one log event.
*
* @param input the input stream
*
- * @return the parsed LogEvent, or {@literal null} of end of input is reached.
+ * @return the parsed LogEvent, never {@literal null}.
* @throws IOException if unable to read from the input
* @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
*/
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2e1815eb/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
index 3428024..660ad80 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/TextLogEventParser.java
@@ -26,14 +26,12 @@ import java.io.Reader;
*/
public interface TextLogEventParser extends LogEventParser {
/**
- * Parse from a Reader. The reader may contain multiple log events.
- * This method will read one log event and leave the reader open and positioned to read the
- * next log event.
+ * Parse from a Reader, which is expected to contain exactly one log event.
*
* @param input the reader
*
- * @return the parsed LogEvent, or {@literal null} of end of input is reached.
- * @throws IOException if unable to read from the input
+ * @return the parsed LogEvent, never {@literal null}.
+ * @throws IOException if unable to read from the Reader
* @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
*/
LogEvent parseFrom(Reader input) throws IOException, ParseException;
@@ -43,7 +41,7 @@ public interface TextLogEventParser extends LogEventParser {
*
* @param input the string
*
- * @return the parsed LogEvent
+ * @return the parsed LogEvent, never {@literal null}.
* @throws ParseException if the input is malformed and cannot be parsed as a LogEvent
*/
LogEvent parseFrom(String input) throws ParseException;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2e1815eb/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
index 597e70b..fdb73fc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/XmlLogEventParser.java
@@ -26,7 +26,7 @@ import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
public class XmlLogEventParser extends AbstractJacksonLogEventParser {
public XmlLogEventParser() {
- super(new Log4jXmlObjectMapper().readerFor(Log4jLogEvent.class));
+ super(new Log4jXmlObjectMapper());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2e1815eb/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
index 59b3463..51a2bfc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/parser/YamlLogEventParser.java
@@ -27,7 +27,7 @@ import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
public class YamlLogEventParser extends AbstractJacksonLogEventParser {
public YamlLogEventParser() {
- super(new Log4jYamlObjectMapper().readerFor(Log4jLogEvent.class));
+ super(new Log4jYamlObjectMapper());
}
}