public class StackdriverJsonLayout
extends 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_NAME
Constructor and Description |
---|
StackdriverJsonLayout()
creates a layout for a Logback appender compatible to the Stackdriver log format.
|
Modifier and Type | Method and Description |
---|---|
void |
addLoggingEventEnhancer(String enhancerClassName)
Add additional logging enhancers that implement
JsonLoggingEventEnhancer . |
protected String |
formatTraceId(String traceId) |
String |
getProjectId()
Get the project id.
|
String |
getSpanIdMDCField()
Get the MDC field name for span id.
|
String |
getTraceIdMDCField()
Get the MDC filed name for trace id.
|
boolean |
isIncludeExceptionInMessage()
check if there is an included exception in the message.
|
boolean |
isIncludeSpanId()
check if the span id is included.
|
boolean |
isIncludeTraceId()
check if the trace id is included.
|
void |
setCustomJson(String json)
set custom json data to include in log output.
|
void |
setIncludeExceptionInMessage(boolean includeExceptionInMessage)
set whether the exception is included in the message.
|
void |
setIncludeSpanId(boolean includeSpanId)
set whether the span id is included.
|
void |
setIncludeTraceId(boolean includeTraceId)
set whether the trace id is included.
|
void |
setProjectId(String projectId)
set the project id.
|
void |
setServiceContext(StackdriverErrorReportingServiceContext serviceContext)
set the service context for stackdriver.
|
void |
setSpanIdMDCField(String spanIdMDCField)
Set the MDC field name for span id.
|
void |
setTraceIdMDCField(String traceIdMDCField)
Set the MDC filed name for trace id.
|
void |
start() |
protected Map<String,Object> |
toJsonMap(ch.qos.logback.classic.spi.ILoggingEvent event)
Convert a logging event into a Map.
|
addCustomDataToJsonMap, addThrowableInfo, getThrowableProxyConverter, isIncludeContextName, isIncludeException, isIncludeFormattedMessage, isIncludeLevel, isIncludeLoggerName, isIncludeMDC, isIncludeMessage, isIncludeThreadName, setIncludeContextName, setIncludeException, setIncludeFormattedMessage, setIncludeLevel, setIncludeLoggerName, setIncludeMDC, setIncludeMessage, setIncludeThreadName, setThrowableProxyConverter, stop
add, addMap, addTimestamp, createDateFormat, doLayout, format, formatTimestamp, getContentType, getJsonFormatter, getTimestampFormat, getTimestampFormatTimezoneId, isAppendLineSeparator, isIncludeTimestamp, setAppendLineSeparator, setIncludeTimestamp, setJsonFormatter, setTimestampFormat, setTimestampFormatTimezoneId
getContext, getFileFooter, getFileHeader, getPresentationFooter, getPresentationHeader, isStarted, setContext, setFileFooter, setFileHeader, setPresentationFooter, setPresentationHeader
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getDeclaredOrigin, getStatusManager
public StackdriverJsonLayout()
public String getProjectId()
public void setProjectId(String projectId)
projectId
- the Google Cloud project id relevant for logging the traceIdpublic String getTraceIdMDCField()
public void setTraceIdMDCField(String traceIdMDCField)
traceIdMDCField
- the MDC field name for retrieving a trace idpublic String getSpanIdMDCField()
public void setSpanIdMDCField(String spanIdMDCField)
spanIdMDCField
- the MDC field name for retrieving a span idpublic boolean isIncludeTraceId()
public void setIncludeTraceId(boolean includeTraceId)
includeTraceId
- true if the traceId should be included into the JSONpublic boolean isIncludeSpanId()
public void setIncludeSpanId(boolean includeSpanId)
includeSpanId
- true if the spanId should be included into the JSONpublic boolean isIncludeExceptionInMessage()
public void setIncludeExceptionInMessage(boolean includeExceptionInMessage)
includeExceptionInMessage
- true if the exception should be added to the messagepublic void setServiceContext(StackdriverErrorReportingServiceContext serviceContext)
serviceContext
- the service contextpublic void setCustomJson(String json)
json
- json stringpublic void addLoggingEventEnhancer(String enhancerClassName)
JsonLoggingEventEnhancer
.enhancerClassName
- class name of the layout enhancerpublic void start()
start
in interface ch.qos.logback.core.spi.LifeCycle
start
in class ch.qos.logback.contrib.json.classic.JsonLayout
protected Map<String,Object> toJsonMap(ch.qos.logback.classic.spi.ILoggingEvent event)
toJsonMap
in class ch.qos.logback.contrib.json.classic.JsonLayout
event
- the logging eventCopyright © 2021. All rights reserved.