You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/05/18 20:40:54 UTC
svn commit: r1595653 [6/11] - in
/logging/log4j/log4j2/branches/experimental: ./
log4j-1.2-api/src/main/java/org/apache/log4j/
log4j-1.2-api/src/test/java/org/apache/log4j/ log4j-api/
log4j-api/src/main/java/org/apache/logging/log4j/ log4j-api/src/main...
Modified: logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JSONLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JSONLayout.java?rev=1595653&r1=1595652&r2=1595653&view=diff
==============================================================================
--- logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JSONLayout.java (original)
+++ logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JSONLayout.java Sun May 18 18:40:48 2014
@@ -18,281 +18,788 @@ package org.apache.logging.log4j.core.la
import java.nio.charset.Charset;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.helpers.Charsets;
-import org.apache.logging.log4j.core.helpers.Throwables;
-import org.apache.logging.log4j.core.helpers.Transform;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.MultiformatMessage;
+import org.apache.logging.log4j.core.util.Charsets;
/**
* Appends a series of JSON events as strings serialized as bytes.
- *
- * TODO: Marker.
- *
+ *
* <h4>Complete well-formed JSON vs. fragment JSON</h4>
* <p>
- * If you configure {@code complete="true"}, the appender outputs a well-formed JSON document.
- * By default, with {@code complete="false"}, you should include the
- * output as an <em>external file</em> in a separate file to form a well-formed JSON document.
+ * If you configure {@code complete="true"}, the appender outputs a well-formed JSON document. By default, with {@code complete="false"},
+ * you should include the output as an <em>external file</em> in a separate file to form a well-formed JSON document.
* </p>
* <p>
- * A well-formed JSON document follows this pattern:
+ * A well-formed JSON event follows this pattern:
* </p>
- *
- * <pre>[
- * {
- * "logger":"com.foo.Bar",
- * "timestamp":"1376681196470",
- * "level":"INFO",
- * "thread":"main",
- * "message":"Message flushed with immediate flush=true"
- * },
- * {
- * "logger":"com.foo.Bar",
- * "timestamp":"1376681196471",
- * "level":"ERROR",
- * "thread":"main",
- * "message":"Message flushed with immediate flush=true",
- * "throwable":"java.lang.IllegalArgumentException: badarg\\n\\tat org.apache.logging.log4j.core.appender.JSONCompleteFileAppenderTest.testFlushAtEndOfBatch(JSONCompleteFileAppenderTest.java:54)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.lang.reflect.Method.invoke(Method.java:606)\\n\\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)\\n\\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\\n\\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)\\n\\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\\n\\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)\\n\\tat org.junit.runners.BlockJUnit4ClassRunner.runChild
(BlockJUnit4ClassRunner.java:70)\\n\\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)\\n\\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)\\n\\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)\\n\\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)\\n\\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)\\n\\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)\\n\\tat org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)\\n\\tat org.junit.runners.ParentRunner.run(ParentRunner.java:309)\\n\\tat org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)\\n\\tat org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remot
eTestRunner.java:683)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)\\n"
- * }
- * ]</pre>
+ *
+ * <pre>
+ * {
+ "timeMillis": 1,
+ "thread": "MyThreadName",
+ "level": "DEBUG",
+ "loggerName": "a.B",
+ "marker": {
+ "name": "Marker1",
+ "parents": [{
+ "name": "ParentMarker1",
+ "parents": [{
+ "name": "GrandMotherMarker"
+ }, {
+ "name": "GrandFatherMarker"
+ }]
+ }, {
+ "name": "GrandFatherMarker"
+ }]
+ },
+ "message": "Msg",
+ "thrown": {
+ "cause": {
+ "commonElementCount": 27,
+ "extendedStackTrace": [{
+ "class": "org.apache.logging.log4j.core.layout.LogEventFixtures",
+ "method": "createLogEvent",
+ "file": "LogEventFixtures.java",
+ "line": 53,
+ "exact": false,
+ "location": "test-classes/",
+ "version": "?"
+ }],
+ "localizedMessage": "testNPEx",
+ "message": "testNPEx",
+ "name": "java.lang.NullPointerException"
+ },
+ "commonElementCount": 0,
+ "extendedStackTrace": [{
+ "class": "org.apache.logging.log4j.core.layout.LogEventFixtures",
+ "method": "createLogEvent",
+ "file": "LogEventFixtures.java",
+ "line": 56,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "org.apache.logging.log4j.core.layout.JSONLayoutTest",
+ "method": "testAllFeatures",
+ "file": "JSONLayoutTest.java",
+ "line": 105,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "org.apache.logging.log4j.core.layout.JSONLayoutTest",
+ "method": "testLocationOnCompactOnMdcOn",
+ "file": "JSONLayoutTest.java",
+ "line": 268,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "sun.reflect.NativeMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "sun.reflect.NativeMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "sun.reflect.DelegatingMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "java.lang.reflect.Method",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "org.junit.runners.model.FrameworkMethod$1",
+ "method": "runReflectiveCall",
+ "file": "FrameworkMethod.java",
+ "line": 47,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.model.ReflectiveCallable",
+ "method": "run",
+ "file": "ReflectiveCallable.java",
+ "line": 12,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.model.FrameworkMethod",
+ "method": "invokeExplosively",
+ "file": "FrameworkMethod.java",
+ "line": 44,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.InvokeMethod",
+ "method": "evaluate",
+ "file": "InvokeMethod.java",
+ "line": 17,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "runLeaf",
+ "file": "ParentRunner.java",
+ "line": 271,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.BlockJUnit4ClassRunner",
+ "method": "runChild",
+ "file": "BlockJUnit4ClassRunner.java",
+ "line": 70,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.BlockJUnit4ClassRunner",
+ "method": "runChild",
+ "file": "BlockJUnit4ClassRunner.java",
+ "line": 50,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$3",
+ "method": "run",
+ "file": "ParentRunner.java",
+ "line": 238,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$1",
+ "method": "schedule",
+ "file": "ParentRunner.java",
+ "line": 63,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "runChildren",
+ "file": "ParentRunner.java",
+ "line": 236,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "access$000",
+ "file": "ParentRunner.java",
+ "line": 53,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$2",
+ "method": "evaluate",
+ "file": "ParentRunner.java",
+ "line": 229,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.RunBefores",
+ "method": "evaluate",
+ "file": "RunBefores.java",
+ "line": 26,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.RunAfters",
+ "method": "evaluate",
+ "file": "RunAfters.java",
+ "line": 27,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "run",
+ "file": "ParentRunner.java",
+ "line": 309,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference",
+ "method": "run",
+ "file": "JUnit4TestReference.java",
+ "line": 50,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.TestExecution",
+ "method": "run",
+ "file": "TestExecution.java",
+ "line": 38,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "runTests",
+ "file": "RemoteTestRunner.java",
+ "line": 467,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "runTests",
+ "file": "RemoteTestRunner.java",
+ "line": 683,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "run",
+ "file": "RemoteTestRunner.java",
+ "line": 390,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "main",
+ "file": "RemoteTestRunner.java",
+ "line": 197,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }],
+ "localizedMessage": "testIOEx",
+ "message": "testIOEx",
+ "name": "java.io.IOException",
+ "suppressed": [{
+ "commonElementCount": 0,
+ "extendedStackTrace": [{
+ "class": "org.apache.logging.log4j.core.layout.LogEventFixtures",
+ "method": "createLogEvent",
+ "file": "LogEventFixtures.java",
+ "line": 57,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "org.apache.logging.log4j.core.layout.JSONLayoutTest",
+ "method": "testAllFeatures",
+ "file": "JSONLayoutTest.java",
+ "line": 105,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "org.apache.logging.log4j.core.layout.JSONLayoutTest",
+ "method": "testLocationOnCompactOnMdcOn",
+ "file": "JSONLayoutTest.java",
+ "line": 268,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "sun.reflect.NativeMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "sun.reflect.NativeMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "sun.reflect.DelegatingMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "java.lang.reflect.Method",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "org.junit.runners.model.FrameworkMethod$1",
+ "method": "runReflectiveCall",
+ "file": "FrameworkMethod.java",
+ "line": 47,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.model.ReflectiveCallable",
+ "method": "run",
+ "file": "ReflectiveCallable.java",
+ "line": 12,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.model.FrameworkMethod",
+ "method": "invokeExplosively",
+ "file": "FrameworkMethod.java",
+ "line": 44,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.InvokeMethod",
+ "method": "evaluate",
+ "file": "InvokeMethod.java",
+ "line": 17,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "runLeaf",
+ "file": "ParentRunner.java",
+ "line": 271,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.BlockJUnit4ClassRunner",
+ "method": "runChild",
+ "file": "BlockJUnit4ClassRunner.java",
+ "line": 70,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.BlockJUnit4ClassRunner",
+ "method": "runChild",
+ "file": "BlockJUnit4ClassRunner.java",
+ "line": 50,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$3",
+ "method": "run",
+ "file": "ParentRunner.java",
+ "line": 238,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$1",
+ "method": "schedule",
+ "file": "ParentRunner.java",
+ "line": 63,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "runChildren",
+ "file": "ParentRunner.java",
+ "line": 236,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "access$000",
+ "file": "ParentRunner.java",
+ "line": 53,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$2",
+ "method": "evaluate",
+ "file": "ParentRunner.java",
+ "line": 229,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.RunBefores",
+ "method": "evaluate",
+ "file": "RunBefores.java",
+ "line": 26,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.RunAfters",
+ "method": "evaluate",
+ "file": "RunAfters.java",
+ "line": 27,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "run",
+ "file": "ParentRunner.java",
+ "line": 309,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference",
+ "method": "run",
+ "file": "JUnit4TestReference.java",
+ "line": 50,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.TestExecution",
+ "method": "run",
+ "file": "TestExecution.java",
+ "line": 38,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "runTests",
+ "file": "RemoteTestRunner.java",
+ "line": 467,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "runTests",
+ "file": "RemoteTestRunner.java",
+ "line": 683,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "run",
+ "file": "RemoteTestRunner.java",
+ "line": 390,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "main",
+ "file": "RemoteTestRunner.java",
+ "line": 197,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }],
+ "localizedMessage": "I am suppressed exception 1",
+ "message": "I am suppressed exception 1",
+ "name": "java.lang.IndexOutOfBoundsException"
+ }, {
+ "commonElementCount": 0,
+ "extendedStackTrace": [{
+ "class": "org.apache.logging.log4j.core.layout.LogEventFixtures",
+ "method": "createLogEvent",
+ "file": "LogEventFixtures.java",
+ "line": 58,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "org.apache.logging.log4j.core.layout.JSONLayoutTest",
+ "method": "testAllFeatures",
+ "file": "JSONLayoutTest.java",
+ "line": 105,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "org.apache.logging.log4j.core.layout.JSONLayoutTest",
+ "method": "testLocationOnCompactOnMdcOn",
+ "file": "JSONLayoutTest.java",
+ "line": 268,
+ "exact": true,
+ "location": "test-classes/",
+ "version": "?"
+ }, {
+ "class": "sun.reflect.NativeMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "sun.reflect.NativeMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "sun.reflect.DelegatingMethodAccessorImpl",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "java.lang.reflect.Method",
+ "method": "invoke",
+ "line": -1,
+ "exact": false,
+ "location": "?",
+ "version": "1.7.0_55"
+ }, {
+ "class": "org.junit.runners.model.FrameworkMethod$1",
+ "method": "runReflectiveCall",
+ "file": "FrameworkMethod.java",
+ "line": 47,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.model.ReflectiveCallable",
+ "method": "run",
+ "file": "ReflectiveCallable.java",
+ "line": 12,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.model.FrameworkMethod",
+ "method": "invokeExplosively",
+ "file": "FrameworkMethod.java",
+ "line": 44,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.InvokeMethod",
+ "method": "evaluate",
+ "file": "InvokeMethod.java",
+ "line": 17,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "runLeaf",
+ "file": "ParentRunner.java",
+ "line": 271,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.BlockJUnit4ClassRunner",
+ "method": "runChild",
+ "file": "BlockJUnit4ClassRunner.java",
+ "line": 70,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.BlockJUnit4ClassRunner",
+ "method": "runChild",
+ "file": "BlockJUnit4ClassRunner.java",
+ "line": 50,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$3",
+ "method": "run",
+ "file": "ParentRunner.java",
+ "line": 238,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$1",
+ "method": "schedule",
+ "file": "ParentRunner.java",
+ "line": 63,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "runChildren",
+ "file": "ParentRunner.java",
+ "line": 236,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "access$000",
+ "file": "ParentRunner.java",
+ "line": 53,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner$2",
+ "method": "evaluate",
+ "file": "ParentRunner.java",
+ "line": 229,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.RunBefores",
+ "method": "evaluate",
+ "file": "RunBefores.java",
+ "line": 26,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.internal.runners.statements.RunAfters",
+ "method": "evaluate",
+ "file": "RunAfters.java",
+ "line": 27,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.junit.runners.ParentRunner",
+ "method": "run",
+ "file": "ParentRunner.java",
+ "line": 309,
+ "exact": true,
+ "location": "junit-4.11.jar",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference",
+ "method": "run",
+ "file": "JUnit4TestReference.java",
+ "line": 50,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.TestExecution",
+ "method": "run",
+ "file": "TestExecution.java",
+ "line": 38,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "runTests",
+ "file": "RemoteTestRunner.java",
+ "line": 467,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "runTests",
+ "file": "RemoteTestRunner.java",
+ "line": 683,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "run",
+ "file": "RemoteTestRunner.java",
+ "line": 390,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }, {
+ "class": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
+ "method": "main",
+ "file": "RemoteTestRunner.java",
+ "line": 197,
+ "exact": true,
+ "location": ".cp/",
+ "version": "?"
+ }],
+ "localizedMessage": "I am suppressed exception 2",
+ "message": "I am suppressed exception 2",
+ "name": "java.lang.IndexOutOfBoundsException"
+ }]
+ },
+ "loggerFQCN": "f.q.c.n",
+ "endOfBatch": false,
+ "contextMap": [{
+ "key": "MDC.B",
+ "value": "B_Value"
+ }, {
+ "key": "MDC.A",
+ "value": "A_Value"
+ }],
+ "contextStack": ["stack_msg1", "stack_msg2"],
+ "source": {
+ "class": "org.apache.logging.log4j.core.layout.LogEventFixtures",
+ "method": "createLogEvent",
+ "file": "LogEventFixtures.java",
+ "line": 54
+ }
+}
+ * </pre>
* <p>
- * If {@code complete="false"}, the appender does not write the JSON open array character "[" at the start of the document.
- * and "]" and the end.
+ * If {@code complete="false"}, the appender does not write the JSON open array character "[" at the start of the document. and "]" and the
+ * end.
* </p>
* <p>
* This approach enforces the independence of the JSONLayout and the appender where you embed it.
* </p>
* <h4>Encoding</h4>
* <p>
- * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise
- * events containing non ASCII characters could result in corrupted log files.
+ * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise events containing non
+ * ASCII characters could result in corrupted log files.
* </p>
* <h4>Pretty vs. compact XML</h4>
* <p>
- * By default, the JSON layout is not compact (a.k.a. not "pretty") with {@code compact="false"}, which means the
- * appender uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no
- * end-of-line or indentation is used. Message content may contain, of course, escaped end-of-lines.
+ * By default, the JSON layout is not compact (a.k.a. not "pretty") with {@code compact="false"}, which means the appender uses end-of-line
+ * characters and indents lines to format the text. If {@code compact="true"}, then no end-of-line or indentation is used. Message content
+ * may contain, of course, escaped end-of-lines.
* </p>
*/
@Plugin(name = "JSONLayout", category = "Core", elementType = "layout", printObject = true)
-public class JSONLayout extends AbstractStringLayout {
-
- private static final int DEFAULT_SIZE = 256;
-
- // We yield to \r\n for the default.
- private static final String DEFAULT_EOL = "\r\n";
- private static final String COMPACT_EOL = "";
- private static final String DEFAULT_INDENT = " ";
- private static final String COMPACT_INDENT = "";
-
- private static final String[] FORMATS = new String[] { "json" };
+public final class JSONLayout extends AbstractJacksonLayout {
- private final boolean locationInfo;
- private final boolean properties;
- private final boolean complete;
- private final String eol;
- private final String indent1;
- private final String indent2;
- private final String indent3;
- private final String indent4;
- private volatile boolean firstLayoutDone;
-
- protected JSONLayout(final boolean locationInfo, final boolean properties, final boolean complete, boolean compact,
+ protected JSONLayout(final boolean locationInfo, final boolean properties, final boolean complete, final boolean compact,
final Charset charset) {
- super(charset);
- this.locationInfo = locationInfo;
- this.properties = properties;
- this.complete = complete;
- this.eol = compact ? COMPACT_EOL : DEFAULT_EOL;
- this.indent1 = compact ? COMPACT_INDENT : DEFAULT_INDENT;
- this.indent2 = this.indent1 + this.indent1;
- this.indent3 = this.indent2 + this.indent1;
- this.indent4 = this.indent3 + this.indent1;
- }
-
- /**
- * Formats a {@link org.apache.logging.log4j.core.LogEvent} in conformance with the log4j.dtd.
- *
- * @param event
- * The LogEvent.
- * @return The XML representation of the LogEvent.
- */
- @Override
- public String toSerializable(final LogEvent event) {
- final StringBuilder buf = new StringBuilder(DEFAULT_SIZE);
- // DC locking to avoid synchronizing the whole layout.
- boolean check = this.firstLayoutDone;
- if (!this.firstLayoutDone) {
- synchronized(this) {
- check = this.firstLayoutDone;
- if (!check) {
- this.firstLayoutDone = true;
- } else {
- buf.append(',');
- buf.append(this.eol);
- }
- }
- } else {
- buf.append(',');
- buf.append(this.eol);
- }
- buf.append(this.indent1);
- buf.append('{');
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"logger\":\"");
- String name = event.getLoggerName();
- if (name.isEmpty()) {
- name = "root";
- }
- buf.append(Transform.escapeJsonControlCharacters(name));
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"timestamp\":\"");
- buf.append(event.getMillis());
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"level\":\"");
- buf.append(Transform.escapeJsonControlCharacters(String.valueOf(event.getLevel())));
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"thread\":\"");
- buf.append(Transform.escapeJsonControlCharacters(event.getThreadName()));
- buf.append("\",");
- buf.append(this.eol);
-
- final Message msg = event.getMessage();
- if (msg != null) {
- boolean jsonSupported = false;
- if (msg instanceof MultiformatMessage) {
- final String[] formats = ((MultiformatMessage) msg).getFormats();
- for (final String format : formats) {
- if (format.equalsIgnoreCase("JSON")) {
- jsonSupported = true;
- break;
- }
- }
- }
- buf.append(this.indent2);
- buf.append("\"message\":\"");
- if (jsonSupported) {
- buf.append(((MultiformatMessage) msg).getFormattedMessage(FORMATS));
- } else {
- buf.append(Transform.escapeJsonControlCharacters(event.getMessage().getFormattedMessage()));
- }
- buf.append('\"');
- }
-
- if (event.getContextStack().getDepth() > 0) {
- buf.append(',');
- buf.append(this.eol);
- buf.append("\"ndc\":");
- buf.append(Transform.escapeJsonControlCharacters(event.getContextStack().toString()));
- buf.append('"');
- }
-
- final Throwable throwable = event.getThrown();
- if (throwable != null) {
- buf.append(',');
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"throwable\":\"");
- final List<String> list = Throwables.toStringList(throwable);
- for (final String str : list) {
- buf.append(Transform.escapeJsonControlCharacters(str));
- buf.append("\\\\n");
- }
- buf.append('"');
- }
-
- if (this.locationInfo) {
- final StackTraceElement element = event.getSource();
- buf.append(',');
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"LocationInfo\":{");
- buf.append(this.eol);
- buf.append(this.indent3);
- buf.append("\"class\":\"");
- buf.append(Transform.escapeJsonControlCharacters(element.getClassName()));
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent3);
- buf.append("\"method\":\"");
- buf.append(Transform.escapeJsonControlCharacters(element.getMethodName()));
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent3);
- buf.append("\"file\":\"");
- buf.append(Transform.escapeJsonControlCharacters(element.getFileName()));
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent3);
- buf.append("\"line\":\"");
- buf.append(element.getLineNumber());
- buf.append('"');
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append('}');
- }
-
- if (this.properties && event.getContextMap().size() > 0) {
- buf.append(',');
- buf.append(this.eol);
- buf.append(this.indent2);
- buf.append("\"Properties\":[");
- buf.append(this.eol);
- final Set<Entry<String, String>> entrySet = event.getContextMap().entrySet();
- int i = 1;
- for (final Map.Entry<String, String> entry : entrySet) {
- buf.append(this.indent3);
- buf.append('{');
- buf.append(this.eol);
- buf.append(this.indent4);
- buf.append("\"name\":\"");
- buf.append(Transform.escapeJsonControlCharacters(entry.getKey()));
- buf.append("\",");
- buf.append(this.eol);
- buf.append(this.indent4);
- buf.append("\"value\":\"");
- buf.append(Transform.escapeJsonControlCharacters(String.valueOf(entry.getValue())));
- buf.append('"');
- buf.append(this.eol);
- buf.append(this.indent3);
- buf.append('}');
- if (i < entrySet.size()) {
- buf.append(',');
- }
- buf.append(this.eol);
- i++;
- }
- buf.append(this.indent2);
- buf.append(']');
- }
-
- buf.append(this.eol);
- buf.append(this.indent1);
- buf.append('}');
-
- return buf.toString();
+ super(new JacksonFactory.JSON().newWriter(locationInfo, properties, compact), charset, compact, complete);
}
/**
* Returns appropriate JSON headers.
- *
+ *
* @return a byte array containing the header, opening the JSON array.
*/
@Override
@@ -308,7 +815,7 @@ public class JSONLayout extends Abstract
/**
* Returns appropriate JSON footer.
- *
+ *
* @return a byte array containing the footer, closing the JSON array.
*/
@Override
@@ -319,15 +826,6 @@ public class JSONLayout extends Abstract
return (this.eol + ']' + this.eol).getBytes(this.getCharset());
}
- /**
- * XMLLayout's content format is specified by:
- * <p/>
- * Key: "dtd" Value: "log4j-events.dtd"
- * <p/>
- * Key: "version" Value: "2.0"
- *
- * @return Map of content format keys supporting XMLLayout
- */
@Override
public Map<String, String> getContentFormat() {
final Map<String, String> result = new HashMap<String, String>();
@@ -345,26 +843,24 @@ public class JSONLayout extends Abstract
/**
* Creates an XML Layout.
- *
- * @param locationInfo
- * If "true", includes the location information in the generated JSON.
- * @param properties
- * If "true", includes the thread context in the generated JSON.
- * @param completeStr
- * If "true", includes the JSON header and footer, defaults to "false".
- * @param compactStr
- * If "true", does not use end-of-lines and indentation, defaults to "false".
- * @param charsetName
- * The character set to use, if {@code null}, uses "UTF-8".
+ *
+ * @param locationInfo If "true", includes the location information in the generated JSON.
+ * @param properties If "true", includes the thread context in the generated JSON.
+ * @param completeStr If "true", includes the JSON header and footer, defaults to "false".
+ * @param compactStr If "true", does not use end-of-lines and indentation, defaults to "false".
+ * @param charsetName The character set to use, if {@code null}, uses "UTF-8".
* @return An XML Layout.
*/
@PluginFactory
- public static JSONLayout createLayout(
+ public static AbstractJacksonLayout createLayout(
+ // @formatter:off
@PluginAttribute("locationInfo") final String locationInfo,
@PluginAttribute("properties") final String properties,
- @PluginAttribute("complete") final String completeStr,
+ @PluginAttribute("complete") final String completeStr,
@PluginAttribute("compact") final String compactStr,
- @PluginAttribute("charset") final String charsetName) {
+ @PluginAttribute("charset") final String charsetName
+ // @formatter:on
+ ) {
final Charset charset = Charsets.getSupportedCharset(charsetName, Charsets.UTF_8);
final boolean info = Boolean.parseBoolean(locationInfo);
final boolean props = Boolean.parseBoolean(properties);
Modified: logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java?rev=1595653&r1=1595652&r2=1595653&view=diff
==============================================================================
--- logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java (original)
+++ logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java Sun May 18 18:40:48 2014
@@ -24,8 +24,8 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.helpers.Booleans;
-import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.core.util.Booleans;
+import org.apache.logging.log4j.core.util.KeyValuePair;
import org.apache.logging.log4j.message.StructuredDataId;
/**
Modified: logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java?rev=1595653&r1=1595652&r2=1595653&view=diff
==============================================================================
--- logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java (original)
+++ logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java Sun May 18 18:40:48 2014
@@ -28,13 +28,13 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.helpers.Booleans;
-import org.apache.logging.log4j.core.helpers.Charsets;
-import org.apache.logging.log4j.core.helpers.OptionConverter;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;
import org.apache.logging.log4j.core.pattern.RegexReplacement;
+import org.apache.logging.log4j.core.util.Booleans;
+import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.OptionConverter;
/**
* <p>A flexible layout configurable with pattern string. The goal of this class
Modified: logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1595653&r1=1595652&r2=1595653&view=diff
==============================================================================
--- logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java (original)
+++ logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java Sun May 18 18:40:48 2014
@@ -38,12 +38,6 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.helpers.Booleans;
-import org.apache.logging.log4j.core.helpers.Charsets;
-import org.apache.logging.log4j.core.helpers.Integers;
-import org.apache.logging.log4j.core.helpers.NetUtils;
-import org.apache.logging.log4j.core.helpers.Patterns;
-import org.apache.logging.log4j.core.helpers.Strings;
import org.apache.logging.log4j.core.net.Facility;
import org.apache.logging.log4j.core.net.Priority;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
@@ -51,9 +45,15 @@ import org.apache.logging.log4j.core.pat
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
+import org.apache.logging.log4j.core.util.Booleans;
+import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Integers;
+import org.apache.logging.log4j.core.util.NetUtils;
+import org.apache.logging.log4j.core.util.Patterns;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.StructuredDataId;
import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.apache.logging.log4j.util.Strings;
/**
@@ -62,7 +62,7 @@ import org.apache.logging.log4j.message.
* @see <a href="https://tools.ietf.org/html/rfc5424">RFC 5424</a>
*/
@Plugin(name = "RFC5424Layout", category = "Core", elementType = "layout", printObject = true)
-public class RFC5424Layout extends AbstractStringLayout {
+public final class RFC5424Layout extends AbstractStringLayout {
private static final String LF = "\n";
@@ -261,7 +261,7 @@ public class RFC5424Layout extends Abstr
public String toSerializable(final LogEvent event) {
final StringBuilder buf = new StringBuilder();
appendPriority(buf, event.getLevel());
- appendTimestamp(buf, event.getMillis());
+ appendTimestamp(buf, event.getTimeMillis());
appendSpace(buf);
appendHostName(buf);
appendSpace(buf);
Modified: logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java?rev=1595653&r1=1595652&r2=1595653&view=diff
==============================================================================
--- logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java (original)
+++ logging/log4j/log4j2/branches/experimental/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java Sun May 18 18:40:48 2014
@@ -31,16 +31,16 @@ import org.apache.logging.log4j.core.Log
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.helpers.Charsets;
import org.apache.logging.log4j.core.net.Facility;
import org.apache.logging.log4j.core.net.Priority;
+import org.apache.logging.log4j.core.util.Charsets;
/**
* Formats a log event as a BSD Log record.
*/
@Plugin(name = "SyslogLayout", category = "Core", elementType = "layout", printObject = true)
-public class SyslogLayout extends AbstractStringLayout {
+public final class SyslogLayout extends AbstractStringLayout {
/**
* Match newlines in a platform-independent manner.
*/
@@ -81,7 +81,7 @@ public class SyslogLayout extends Abstra
buf.append('<');
buf.append(Priority.getPriority(facility, event.getLevel()));
buf.append('>');
- addDate(event.getMillis(), buf);
+ addDate(event.getTimeMillis(), buf);
buf.append(' ');
buf.append(localHostname);
buf.append(' ');