No description or website provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Kafka logback appender

This is a logback appender for Kafka ( kafka-client used) This appender expects topic, bootstrapServers, valueSerializer and layout as mandatory. You could also supply additional kafka customProps in <customProps> tag in the following manner <customProps>key1|value1,key2|value2</customProps>

We recommend wrapping this appender inside AsyncAppender in order not to block your application (consider setting neverBlock to true). This appender ships with CustomJsonLayout, which extends JsonLayout from logback. It inherits all its properties and adds its own in the same manner. List of properties added: includeLineNumber, includeClassName, includeMethodName, includeHost, includeFileName all set to true by default. You can also add any constant fields via additionalFields (see sample config below).

Do not forget to add `true` to AsyncAppender in case you need caller data (method, class, file, line number). Kafka appender could be used with any other layout rather than Json, just think about proper kafka value Serializer.

Sample configuration

<?xml version="1.0" encoding="UTF-8"?>

    <appender name="KAFKA" class="ru.sberned.kafkalogback.KafkaAppender">
        <layout class="ru.sberned.kafkalogback.CustomJsonLayout">
            <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter"/>

    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="KAFKA" />

    <!-- Do not sent kafka client logs to kafka. This way you could fill all the queue of AsyncAppender-->
    <logger name="org.apache.kafka" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />

    <!-- Please note. CONSOLE and FILE appenders are not defined in this example -->
    <root level="TRACE">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
        <appender-ref ref="ASYNC" />