public class JsonLayout
extends org.apache.log4j.Layout
The JSON object will always contain the following properties, most of which
are extracted from the Log4J LoggingEvent
timestamp: the date/time that the message was logged.
thread: the name of the thread where the message was logged.
logger: the name of the logger.
level: the level of this log message.
message: the message itself.
processId: the PID of the invoking process, if available (this is
retrieved from RuntimeMxBean and may not be
available on all platforms).
The following properties will only appear if they are present in the event:
exception: the stack trace of an associated exception. This
is exposed as an array of strings, with the first
element being the location where the exception
was caught.
mdc: the mapped diagnostic context. This is a child map.
ndc: the nested diagnostic context. This is a single
string that contains each of the pushed entries
separated by spaces (yes, that's how Log4J does it).
The following properties are potentially expensive to compute, so will only appear if specifically enabled via configuration:
locationInfo: the location where the logger was called. This is a
child object with the following components:
className
methodName
fileName
lineNumber
instanceId: the EC2 instance ID of the machine where the logger is
running. WARNING: do not enable this elsewhere, as the
operation to retrieve this value may take a long time.
hostname: the name of the machine where the logger is running, if
available (this is currently retrieved from
RuntimeMxBean and may not be available on
all platforms).
Lastly, you can define a set of user tags, which are written as a child object with
the key tags. These are intended to provide program-level information,
in the case where multiple programs send their logs to the same stream. They are set
as a single comma-separate string, which may contain substitution values (example:
appName=Fribble,startedAt={startupTimestamp}).
WARNING: you should not rely on the order in which elements are output. Any apparent ordering is an implementation choice and subject to change without notice.
| Constructor and Description |
|---|
JsonLayout() |
| Modifier and Type | Method and Description |
|---|---|
void |
activateOptions() |
String |
format(org.apache.log4j.spi.LoggingEvent event) |
boolean |
getAppendNewlines() |
boolean |
getEnableHostname() |
boolean |
getEnableInstanceId() |
boolean |
getEnableLocation() |
String |
getTags() |
boolean |
ignoresThrowable() |
void |
setAppendNewlines(boolean value) |
void |
setEnableHostname(boolean value) |
void |
setEnableInstanceId(boolean value) |
void |
setEnableLocation(boolean value) |
void |
setTags(String value) |
public void setAppendNewlines(boolean value)
public boolean getAppendNewlines()
public void setEnableLocation(boolean value)
public boolean getEnableLocation()
public void setEnableInstanceId(boolean value)
public boolean getEnableInstanceId()
public void setEnableHostname(boolean value)
public boolean getEnableHostname()
public void setTags(String value)
public String getTags()
public void activateOptions()
public String format(org.apache.log4j.spi.LoggingEvent event)
format in class org.apache.log4j.Layoutpublic boolean ignoresThrowable()
ignoresThrowable in class org.apache.log4j.LayoutCopyright © 2018. All rights reserved.