Configuration¶
The following example shows the available settings. Only url and index are
required for Elasticsearch or OpenSearch delivery.
<appender name="ELASTIC"
class="com.agido.logback.elasticsearch.ElasticsearchAppender">
<url>http://yourserver/_bulk</url>
<index>logs-%date{yyyy-MM-dd}</index>
<type>tester</type>
<loggerName>es-logger</loggerName>
<errorLoggerName>es-error-logger</errorLoggerName>
<connectTimeout>30000</connectTimeout>
<readTimeout>30000</readTimeout>
<shutdownTimeout>30000</shutdownTimeout>
<sleepTime>250</sleepTime>
<maxQueueSize>104857600</maxQueueSize>
<maxRetries>3</maxRetries>
<maxBatchSize>-1</maxBatchSize>
<includeCallerData>false</includeCallerData>
<errorsToStderr>false</errorsToStderr>
<logsToStderr>false</logsToStderr>
<rawJsonMessage>false</rawJsonMessage>
<includeMdc>false</includeMdc>
<includeKvp>false</includeKvp>
<maxMessageSize>-1</maxMessageSize>
<objectSerialization>false</objectSerialization>
<keyPrefix>data.</keyPrefix>
<operation>create</operation>
<timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSSZ</timestampFormat>
<properties>
<esProperty>
<name>host</name>
<value>${HOSTNAME}</value>
<allowEmpty>false</allowEmpty>
</esProperty>
<esProperty>
<name>severity</name>
<value>%level</value>
</esProperty>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
Configuration reference¶
url(required): Elasticsearch or OpenSearch Bulk API endpoint.index(required): Target index. Supports LogbackPatternLayoutconversion words, for examplelogs-%date{yyyy-MM-dd}.type(optional): Adds_typeto each bulk action. Leave this unset for current Elasticsearch and OpenSearch versions; configure it only for a legacy API and mapping that still require document types.sleepTime(default250ms, minimum100): Delay when the event queue is empty. The queue is drained before sleeping.maxBatchSize(default-1): Maximum events per batch. A positive number limits the batch;-1drains the entire queue.maxRetries(default3): Retry attempts for pending data. A later event resets the retry count.connectTimeout(default30000ms): HTTP connection timeout.readTimeout(default30000ms): HTTP request timeout.shutdownTimeout(default30000ms): Maximum wait for the worker during Logback shutdown.0waits indefinitely.maxQueueSize(default104857600characters): Approximate send-buffer limit. New log data is dropped while the limit is exceeded.includeCallerData(defaultfalse): Capture caller data before asynchronous processing.errorsToStderr(defaultfalse): Also write delivery errors to stderr. Errors otherwise use Logback's internal status system.logsToStderr(defaultfalse): Write raw Bulk API payloads to stderr.loggerName(optional): Send raw Bulk API payloads to this logger.errorLoggerName(optional): Send internal errors to this logger.rawJsonMessage(defaultfalse): Treat the log message as preformatted JSON.includeMdc(defaultfalse): Add all MDC values to the JSON payload.includeKvp(defaultfalse): Add key-value pairs created with SLF4J's fluentLoggingEventBuilderAPI.maxMessageSize(default-1): For values greater than0, truncate longer messages and append...authentication(optional): Authentication implementation; see Authentication.objectSerialization(defaultfalse): Enable Jackson POJO-to-JSON serialization and automatic module discovery.keyPrefix(optional): Prefix for objects extracted from a structured message.operation(defaultcreate): Bulk operation:index,create,update, ordelete.timestampFormat(optional): Custom timestamp format. Uselongfor epoch milliseconds.
The @timestamp and message fields are always sent. Additional fields use
<esProperty> entries:
name(required): JSON field name.value(required): Value rendered through LogbackPatternLayout, including conversion words and substitutions such as${HOSTNAME}.allowEmpty(defaultfalse): Include a field whose rendered value is null or empty.type(defaultString): One ofString,int,float, orboolean.