Examples

MDC and fluent key-value pairs

<includeMdc>true</includeMdc>
<includeKvp>true</includeKvp>

includeKvp applies to key-value pairs added through SLF4J 2's fluent API.

Raw JSON messages

<rawJsonMessage>true</rawJsonMessage>

With this option enabled, the message is inserted as preformatted JSON. Only use it when the application controls and validates the JSON content.

Logback Access

For access events, use:

<appender name="ELASTIC_ACCESS"
          class="com.agido.logback.elasticsearch.ElasticsearchAccessAppender">
    <!-- Same core settings as above -->
</appender>

Property values use Logback Access conversion words.

Groovy configuration

import com.agido.logback.elasticsearch.ElasticsearchAppender
import com.agido.logback.elasticsearch.config.BasicAuthentication
import com.agido.logback.elasticsearch.config.HttpRequestHeader
import com.agido.logback.elasticsearch.config.HttpRequestHeaders

appender("ELASTIC", ElasticsearchAppender) {
    url = "http://yourserver/_bulk"
    index = "logs-%date{yyyy-MM-dd}"
    rawJsonMessage = true
    errorsToStderr = true
    authentication = new BasicAuthentication()
    def configHeaders = new HttpRequestHeaders()
    configHeaders.addHeader(new HttpRequestHeader(
            name: "Content-Type", value: "application/json"))
    headers = configHeaders
}

root(INFO, ["ELASTIC"])