Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.logging.log4j.core.layout
Class JsonLayout

    java.lang.Object
      org.apache.logging.log4j.core.layout.AbstractLayout<String>
          org.apache.logging.log4j.core.layout.AbstractStringLayout
              org.apache.logging.log4j.core.layout.JsonLayout

All Implemented Interfaces:
  Serializable, Layout<String>

    @Plugin(name="JsonLayout",
            category="Core",
            elementType="layout",
            printObject=true)
    public final class JsonLayout

extends AbstractStringLayout

Appends a series of JSON events as strings serialized as bytes.

### Complete well-formed JSON vs. fragment JSON

If you configure `complete="true"`, the appender outputs a well-formed JSON document. By default, with `complete="false"`, you should include the output as an external file in a separate file to form a well-formed JSON document.

A well-formed JSON event follows this pattern:

     {
      "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
      }
    }

If `complete="false"`, the appender does not write the JSON open array character "[" at the start of the document. and "]" and the end.

This approach enforces the independence of the JsonLayout and the appender where you embed it.

### Encoding

Appenders using this layout should have their `charset` set to `UTF-8` or `UTF-16`, otherwise events containing non ASCII characters could result in corrupted log files.

### Pretty vs. compact XML

By default, the JSON layout is not compact (a.k.a. not "pretty") with `compact="false"`, which means the appender uses end-of-line characters and indents lines to format the text. If `compact="true"`, then no end-of-line or indentation is used. Message content may contain, of course, escaped end-of-lines.

See Also:
  Serialized Form

Field Summary
`protected boolean` | `compact`
`protected static String` | `COMPACT_EOL`
`protected boolean` | `complete`
`protected static String` | `DEFAULT_EOL`
`protected String` | `eol`
`protected com.fasterxml.jackson.databind.ObjectWriter` | `objectWriter`

Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
`footer, header, LOGGER`

Fields inherited from interface org.apache.logging.log4j.core.Layout
`ELEMENT_TYPE`

Constructor Summary
`protected` | `JsonLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, Charset charset)`

Method Summary
`static org.apache.logging.log4j.core.layout.AbstractJacksonLayout` | `createDefaultLayout()` Creates a JSON Layout using the default settings.
`static org.apache.logging.log4j.core.layout.AbstractJacksonLayout` | `createLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, Charset charset)` Creates a JSON Layout.
`Map<String,String>` | `getContentFormat()` Returns a description of the content format.
`String` | `getContentType()` Returns the content type output by this layout.
`byte[]` | `getFooter()` Returns appropriate JSON footer.
`byte[]` | `getHeader()` Returns appropriate JSON header.
`String` | `toSerializable(LogEvent event)` Formats a `LogEvent`.

Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
`getBytes, getCharset, toByteArray`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_EOL

    protected static final String DEFAULT_EOL

See Also:
  Constant Field Values

### COMPACT_EOL

    protected static final String COMPACT_EOL

See Also:
  Constant Field Values

### eol

    protected final String eol

### objectWriter

    protected final com.fasterxml.jackson.databind.ObjectWriter objectWriter

### compact

    protected final boolean compact

### complete

    protected final boolean complete

Constructor Detail

### JsonLayout

    protected JsonLayout(boolean locationInfo,
                         boolean properties,
                         boolean complete,
                         boolean compact,
                         boolean eventEol,
                         Charset charset)

Method Detail

### getHeader

    public byte[] getHeader()

  Returns appropriate JSON header.

  Specified by:
    `getHeader` in interface `Layout<String>`
  Overrides:
    `getHeader` in class `AbstractLayout<String>`
  Returns:
    a byte array containing the header, opening the JSON array.

### getFooter

    public byte[] getFooter()

  Returns appropriate JSON footer.

  Specified by:
    `getFooter` in interface `Layout<String>`
  Overrides:
    `getFooter` in class `AbstractLayout<String>`
  Returns:
    a byte array containing the footer, closing the JSON array.

### getContentFormat

    public Map<String,String> getContentFormat()

  Description copied from interface: `Layout`
  Returns a description of the content format.

  Specified by:
    `getContentFormat` in interface `Layout<String>`
  Overrides:
    `getContentFormat` in class `AbstractLayout<String>`
  Returns:
    a Map of key/value pairs describing the Layout-specific content format, or an empty Map if no content format descriptors are specified.

### getContentType

    public String getContentType()

  Description copied from interface: `Layout`
  Returns the content type output by this layout. The base class returns "text/plain".

  Specified by:
    `getContentType` in interface `Layout<String>`
  Overrides:
    `getContentType` in class `AbstractStringLayout`
  Returns:
    The default content type for Strings.

### createLayout

    @PluginFactory
    public static org.apache.logging.log4j.core.layout.AbstractJacksonLayout createLayout(@PluginAttribute(value="locationInfo",defaultBoolean=false)
                                                                                                        boolean locationInfo,
                                                                                                        @PluginAttribute(value="properties",defaultBoolean=false)
                                                                                                        boolean properties,
                                                                                                        @PluginAttribute(value="complete",defaultBoolean=false)
                                                                                                        boolean complete,
                                                                                                        @PluginAttribute(value="compact",defaultBoolean=false)
                                                                                                        boolean compact,
                                                                                                        @PluginAttribute(value="eventEol",defaultBoolean=false)
                                                                                                        boolean eventEol,
                                                                                                        @PluginAttribute(value="charset",defaultString="UTF-8")
                                                                                                        Charset charset)

  Creates a JSON Layout.

  Parameters:
    `locationInfo` - If "true", includes the location information in the generated JSON.
    `properties` - If "true", includes the thread context in the generated JSON.
    `complete` - If "true", includes the JSON header and footer, defaults to "false".
    `compact` - If "true", does not use end-of-lines and indentation, defaults to "false".
    `eventEol` - If "true", forces an EOL after each log event (even if compact is "true"), defaults to "false". This allows one even per line, even in compact mode.
    `charset` - The character set to use, if `null`, uses "UTF-8".
  Returns:
    A JSON Layout.

### createDefaultLayout

    public static org.apache.logging.log4j.core.layout.AbstractJacksonLayout createDefaultLayout()

  Creates a JSON Layout using the default settings.

  Returns:
    A JSON Layout.

### toSerializable

    public String toSerializable(LogEvent event)

  Formats a `LogEvent`.

  Parameters:
    `event` - The LogEvent.
  Returns:
    The XML representation of the LogEvent.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.