Package com.google.cloud.spring.logging
Class StackdriverJsonLayout
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.LayoutBase<E>
ch.qos.logback.contrib.json.JsonLayoutBase<ch.qos.logback.classic.spi.ILoggingEvent>
ch.qos.logback.contrib.json.classic.JsonLayout
com.google.cloud.spring.logging.StackdriverJsonLayout
- 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 StackdriverJsonLayout
extends ch.qos.logback.contrib.json.classic.JsonLayout
This class provides a JSON layout for a Logback appender compatible to the Stackdriver log
format.
Reference: https://cloud.google.com/logging/docs/agent/configuration#process-payload
-
Field Summary
Fields inherited from class ch.qos.logback.contrib.json.classic.JsonLayout
CONTEXT_ATTR_NAME, EXCEPTION_ATTR_NAME, FORMATTED_MESSAGE_ATTR_NAME, includeContextName, includeException, includeFormattedMessage, includeLevel, includeLoggerName, includeMDC, includeMessage, includeThreadName, LEVEL_ATTR_NAME, LOGGER_ATTR_NAME, MDC_ATTR_NAME, MESSAGE_ATTR_NAME, THREAD_ATTR_NAME, TIMESTAMP_ATTR_NAMEFields inherited from class ch.qos.logback.contrib.json.JsonLayoutBase
appendLineSeparator, CONTENT_TYPE, includeTimestamp, jsonFormatter, timestampFormat, timestampFormatTimezoneIdFields inherited from class ch.qos.logback.core.LayoutBase
startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
ConstructorsConstructorDescriptioncreates a layout for a Logback appender compatible to the Stackdriver log format. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLoggingEventEnhancer(String enhancerClassName) Add additional logging enhancers that implementJsonLoggingEventEnhancer.protected StringformatTraceId(String traceId) Get the project id.Get the MDC field name for span id.Get the MDC filed name for trace id.booleancheck if there is an included exception in the message.booleancheck if the span id is included.booleancheck if the trace id is included.voidsetCustomJson(String json) set custom json data to include in log output.voidsetIncludeExceptionInMessage(boolean includeExceptionInMessage) set whether the exception is included in the message.voidsetIncludeSpanId(boolean includeSpanId) set whether the span id is included.voidsetIncludeTraceId(boolean includeTraceId) set whether the trace id is included.voidsetProjectId(String projectId) set the project id.voidsetServiceContext(StackdriverErrorReportingServiceContext serviceContext) set the service context for stackdriver.voidsetSpanIdMdcField(String spanIdMdcField) Set the MDC field name for span id.voidsetTraceIdMdcField(String traceIdMdcField) Set the MDC filed name for trace id.voidstart()toJsonMap(ch.qos.logback.classic.spi.ILoggingEvent event) Convert a logging event into a Map.Methods inherited from class ch.qos.logback.contrib.json.classic.JsonLayout
addCustomDataToJsonMap, addThrowableInfo, getThrowableProxyConverter, isIncludeContextName, isIncludeException, isIncludeFormattedMessage, isIncludeLevel, isIncludeLoggerName, isIncludeMDC, isIncludeMessage, isIncludeThreadName, setIncludeContextName, setIncludeException, setIncludeFormattedMessage, setIncludeLevel, setIncludeLoggerName, setIncludeMDC, setIncludeMessage, setIncludeThreadName, setThrowableProxyConverter, stopMethods inherited from class ch.qos.logback.contrib.json.JsonLayoutBase
add, addMap, addTimestamp, createDateFormat, doLayout, format, formatTimestamp, getContentType, getJsonFormatter, getTimestampFormat, getTimestampFormatTimezoneId, isAppendLineSeparator, isIncludeTimestamp, setAppendLineSeparator, setIncludeTimestamp, setJsonFormatter, setTimestampFormat, setTimestampFormatTimezoneIdMethods inherited from class ch.qos.logback.core.LayoutBase
getContext, getFileFooter, getFileHeader, getPresentationFooter, getPresentationHeader, isStarted, setContext, setFileFooter, setFileHeader, setPresentationFooter, setPresentationHeaderMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getDeclaredOrigin, getStatusManagerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn
-
Constructor Details
-
StackdriverJsonLayout
public StackdriverJsonLayout()creates a layout for a Logback appender compatible to the Stackdriver log format.
-
-
Method Details
-
getProjectId
Get the project id.- Returns:
- the Google Cloud project id relevant for logging the traceId
-
setProjectId
set the project id.- Parameters:
projectId- the Google Cloud project id relevant for logging the traceId
-
getTraceIdMdcField
Get the MDC filed name for trace id.- Returns:
- the MDC field name for retrieving a trace id
- Since:
- 2.0.5
-
setTraceIdMdcField
Set the MDC filed name for trace id.- Parameters:
traceIdMdcField- the MDC field name for retrieving a trace id- Since:
- 2.0.5
-
getSpanIdMdcField
Get the MDC field name for span id.- Returns:
- the MDC field name for retrieving a span id
- Since:
- 2.0.5
-
setSpanIdMdcField
Set the MDC field name for span id.- Parameters:
spanIdMdcField- the MDC field name for retrieving a span id- Since:
- 2.0.5
-
isIncludeTraceId
public boolean isIncludeTraceId()check if the trace id is included.- Returns:
- true if the traceId should be included into the JSON
-
setIncludeTraceId
public void setIncludeTraceId(boolean includeTraceId) set whether the trace id is included.- Parameters:
includeTraceId- true if the traceId should be included into the JSON
-
isIncludeSpanId
public boolean isIncludeSpanId()check if the span id is included.- Returns:
- true if the spanId should be included into the JSON
-
setIncludeSpanId
public void setIncludeSpanId(boolean includeSpanId) set whether the span id is included.- Parameters:
includeSpanId- true if the spanId should be included into the JSON
-
isIncludeExceptionInMessage
public boolean isIncludeExceptionInMessage()check if there is an included exception in the message.- Returns:
- true if the exception should be added to the message
-
setIncludeExceptionInMessage
public void setIncludeExceptionInMessage(boolean includeExceptionInMessage) set whether the exception is included in the message.- Parameters:
includeExceptionInMessage- true if the exception should be added to the message
-
setServiceContext
set the service context for stackdriver.- Parameters:
serviceContext- the service context- Since:
- 1.2
-
setCustomJson
set custom json data to include in log output.- Parameters:
json- json string- Since:
- 1.2
-
addLoggingEventEnhancer
Add additional logging enhancers that implementJsonLoggingEventEnhancer.- Parameters:
enhancerClassName- class name of the layout enhancer
-
start
public void start()- Specified by:
startin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
startin classch.qos.logback.contrib.json.classic.JsonLayout
-
toJsonMap
Convert a logging event into a Map.- Overrides:
toJsonMapin classch.qos.logback.contrib.json.classic.JsonLayout- Parameters:
event- the logging event- Returns:
- the map which should get rendered as JSON
-
formatTraceId
-