ch.qos.logback.contrib.json.classic
Class JsonLayout

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.LayoutBase<E>
          extended by ch.qos.logback.contrib.json.JsonLayoutBase<ch.qos.logback.classic.spi.ILoggingEvent>
              extended by ch.qos.logback.contrib.json.classic.JsonLayout
All Implemented Interfaces:
ch.qos.logback.core.Layout<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.LifeCycle

public class JsonLayout
extends JsonLayoutBase<ch.qos.logback.classic.spi.ILoggingEvent>

A JsonLayout builds its jsonMap from a source ILoggingEvent with the following keys/value pairs:

Key Value Notes Enabled by default?
timestamp String value of ILoggingEvent.getTimeStamp() By default, the value is not formatted; it is simply String.valueOf(timestamp). To format the string using a SimpleDateFormat, set the timestampFormat property with the corresponding SimpleDateFormat string, for example, yyyy-MM-dd HH:mm:ss.SSS true
level String value of ILoggingEvent.getLevel() String.valueOf(event.getLevel()); true
thread ILoggingEvent.getThreadName() true
mdc ILoggingEvent.getMDCPropertyMap() Unlike the other values which are all Strings, this value is a Map&lt;String,String&gt;. If there is no MDC, this property will not be added to the JSON map. true
thread ILoggingEvent.getLoggerName() true
message ILoggingEvent.getFormattedMessage() This is the formatted message. The raw (unformatted) message is available as raw-message. Most people will want the formatted message as the raw message does not reflect any log message arguments. true
raw-message ILoggingEvent.getMessage() false
exception ILoggingEvent.getThrowableProxy() If there is no exception, this property will not be added to the JSON map. If there is an exception, it will be formatted to a String first via a ThrowableProxyConverter. true
context ILoggingEvent.getLoggerContextVO() The name of the logger context. Defaults to default. true

The constructed Map will be serialized to JSON via the parent class's jsonFormatter.

Since:
0.1
Author:
Les Hazlewood, Pierre Queinnec

Field Summary
static String CONTEXT_ATTR_NAME
           
static String EXCEPTION_ATTR_NAME
           
static String FORMATTED_MESSAGE_ATTR_NAME
           
protected  boolean includeContextName
           
protected  boolean includeException
           
protected  boolean includeFormattedMessage
           
protected  boolean includeLevel
           
protected  boolean includeLoggerName
           
protected  boolean includeMDC
           
protected  boolean includeMessage
           
protected  boolean includeThreadName
           
static String LEVEL_ATTR_NAME
           
static String LOGGER_ATTR_NAME
           
static String MDC_ATTR_NAME
           
static String MESSAGE_ATTR_NAME
           
static String THREAD_ATTR_NAME
           
static String TIMESTAMP_ATTR_NAME
           
 
Fields inherited from class ch.qos.logback.contrib.json.JsonLayoutBase
appendLineSeparator, CONTENT_TYPE, includeTimestamp, jsonFormatter, timestampFormat, timestampFormatTimezoneId
 
Fields inherited from class ch.qos.logback.core.LayoutBase
started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
JsonLayout()
           
 
Method Summary
 boolean isIncludeContextName()
           
 boolean isIncludeException()
           
 boolean isIncludeFormattedMessage()
           
 boolean isIncludeLevel()
           
 boolean isIncludeLoggerName()
           
 boolean isIncludeMDC()
           
 boolean isIncludeMessage()
           
 boolean isIncludeThreadName()
           
 void setIncludeContextName(boolean includeContextName)
           
 void setIncludeException(boolean includeException)
           
 void setIncludeFormattedMessage(boolean includeFormattedMessage)
           
 void setIncludeLevel(boolean includeLevel)
           
 void setIncludeLoggerName(boolean includeLoggerName)
           
 void setIncludeMDC(boolean includeMDC)
           
 void setIncludeMessage(boolean includeMessage)
           
 void setIncludeThreadName(boolean includeThreadName)
           
 void start()
           
 void stop()
           
protected  Map toJsonMap(ch.qos.logback.classic.spi.ILoggingEvent event)
           
 
Methods inherited from class ch.qos.logback.contrib.json.JsonLayoutBase
createDateFormat, doLayout, format, formatTimestamp, getContentType, getJsonFormatter, getTimestampFormat, getTimestampFormatTimezoneId, isAppendLineSeparator, isIncludeTimestamp, setAppendLineSeparator, setIncludeTimestamp, setJsonFormatter, setTimestampFormat, setTimestampFormatTimezoneId
 
Methods inherited from class ch.qos.logback.core.LayoutBase
getContext, getFileFooter, getFileHeader, getPresentationFooter, getPresentationHeader, isStarted, setContext, setFileFooter, setFileHeader, setPresentationFooter, setPresentationHeader
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getDeclaredOrigin, getStatusManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn
 

Field Detail

TIMESTAMP_ATTR_NAME

public static final String TIMESTAMP_ATTR_NAME
See Also:
Constant Field Values

LEVEL_ATTR_NAME

public static final String LEVEL_ATTR_NAME
See Also:
Constant Field Values

THREAD_ATTR_NAME

public static final String THREAD_ATTR_NAME
See Also:
Constant Field Values

MDC_ATTR_NAME

public static final String MDC_ATTR_NAME
See Also:
Constant Field Values

LOGGER_ATTR_NAME

public static final String LOGGER_ATTR_NAME
See Also:
Constant Field Values

FORMATTED_MESSAGE_ATTR_NAME

public static final String FORMATTED_MESSAGE_ATTR_NAME
See Also:
Constant Field Values

MESSAGE_ATTR_NAME

public static final String MESSAGE_ATTR_NAME
See Also:
Constant Field Values

EXCEPTION_ATTR_NAME

public static final String EXCEPTION_ATTR_NAME
See Also:
Constant Field Values

CONTEXT_ATTR_NAME

public static final String CONTEXT_ATTR_NAME
See Also:
Constant Field Values

includeLevel

protected boolean includeLevel

includeThreadName

protected boolean includeThreadName

includeMDC

protected boolean includeMDC

includeLoggerName

protected boolean includeLoggerName

includeFormattedMessage

protected boolean includeFormattedMessage

includeMessage

protected boolean includeMessage

includeException

protected boolean includeException

includeContextName

protected boolean includeContextName
Constructor Detail

JsonLayout

public JsonLayout()
Method Detail

start

public void start()
Specified by:
start in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
start in class ch.qos.logback.core.LayoutBase<ch.qos.logback.classic.spi.ILoggingEvent>

stop

public void stop()
Specified by:
stop in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
stop in class ch.qos.logback.core.LayoutBase<ch.qos.logback.classic.spi.ILoggingEvent>

toJsonMap

protected Map toJsonMap(ch.qos.logback.classic.spi.ILoggingEvent event)
Specified by:
toJsonMap in class JsonLayoutBase<ch.qos.logback.classic.spi.ILoggingEvent>

isIncludeLevel

public boolean isIncludeLevel()

setIncludeLevel

public void setIncludeLevel(boolean includeLevel)

isIncludeLoggerName

public boolean isIncludeLoggerName()

setIncludeLoggerName

public void setIncludeLoggerName(boolean includeLoggerName)

isIncludeFormattedMessage

public boolean isIncludeFormattedMessage()

setIncludeFormattedMessage

public void setIncludeFormattedMessage(boolean includeFormattedMessage)

isIncludeMessage

public boolean isIncludeMessage()

setIncludeMessage

public void setIncludeMessage(boolean includeMessage)

isIncludeMDC

public boolean isIncludeMDC()

setIncludeMDC

public void setIncludeMDC(boolean includeMDC)

isIncludeThreadName

public boolean isIncludeThreadName()

setIncludeThreadName

public void setIncludeThreadName(boolean includeThreadName)

isIncludeException

public boolean isIncludeException()

setIncludeException

public void setIncludeException(boolean includeException)

isIncludeContextName

public boolean isIncludeContextName()

setIncludeContextName

public void setIncludeContextName(boolean includeContextName)


Copyright © 2012-2013. All Rights Reserved.