### Full Logback Configuration with Kafka Appender
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
A complete `logback.xml` example demonstrating how to configure the `KafkaAppender`. It includes a `ConsoleAppender` for fallback, defines the Kafka topic, keying and delivery strategies, and sets mandatory producer configurations like `bootstrap.servers`.
```XML
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
logs
bootstrap.servers=localhost:9092
```
--------------------------------
### Configure Logback Kafka Appender with AsyncAppender
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Example configuration showing how to wrap the `KafkaAppender` with Logback's `AsyncAppender` to prevent application blocking, especially during Kafka broker outages, by setting `neverBlock` to true.
```XML
true
```
--------------------------------
### Add logback-kafka-appender Project Dependencies
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Instructions for adding `logback-kafka-appender` and `logback-classic` as library dependencies to your project using different build tools.
```XML
com.github.danielwegener
logback-kafka-appender
0.2.0
runtime
ch.qos.logback
logback-classic
1.2.3
runtime
```
```Scala
// [build.sbt]
libraryDependencies += "com.github.danielwegener" % "logback-kafka-appender" % "0.2.0"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
```
--------------------------------
### Implement Custom Keying Strategy for Logback Kafka Appender
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Demonstrates how to create a custom `KeyingStrategy` by implementing the `com.github.danielwegener.logback.kafka.keying.KeyingStrategy` interface. This allows developers to define their own logic for generating Kafka message keys, which is crucial for controlling message partitioning and ordering, especially useful for scenarios like Kafka's log compaction facility.
```Java
package foo;
import com.github.danielwegener.logback.kafka.keying.KeyingStrategy;
/* This is a valid example but does not really make much sense */
public class LevelKeyingStrategy implements KeyingStrategy {
@Override
public byte[] createKey(ILoggingEvent e) {
return ByteBuffer.allocate(4).putInt(e.getLevel()).array();
}
}
```
--------------------------------
### Logback Kafka Appender: Built-in Keying Strategies
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Describes the default and available built-in keying strategies for the logback-kafka-appender, which determine how log messages are partitioned across Kafka topics. Each strategy influences message ordering guarantees within partitions and the distribution balance across all available partitions.
```APIDOC
Keying Strategies:
NoKeyKeyingStrategy (default):
Description: Does not generate a message key. Results in round robin distribution across partitions if no fixed partition is provided.
HostNameKeyingStrategy:
Description: Uses the HOSTNAME as message key. Ensures all log messages issued by this host will remain in the correct order for any consumer. Can lead to uneven log distribution for a small number of hosts compared to the number of partitions.
ContextNameKeyingStrategy:
Description: Uses logback's CONTEXT_NAME as message key. Ensures all log messages logged by the same logging context will remain in the correct order for any consumer. This strategy only works for ILoggingEvents. Can lead to uneven log distribution for a small number of contexts.
ThreadNameKeyingStrategy:
Description: Uses the calling thread's name as message key. Ensures all messages logged by the same thread will remain in the correct order for any consumer. This strategy only works for ILoggingEvents. Can lead to uneven log distribution for a small number of threads.
LoggerNameKeyingStrategy:
Description: Uses the logger name as message key. Ensures all messages logged by the same logger will remain in the correct order for any consumer. This strategy only works for ILoggingEvents. Can lead to uneven log distribution for a small number of distinct loggers.
```
--------------------------------
### Kafka Appender Delivery Strategies
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Details the available delivery strategies for the Logback Kafka Appender, outlining their behavior, advantages, and limitations regarding message delivery and application performance.
```APIDOC
Strategy: AsynchronousDeliveryStrategy
Description: Dispatches each log message to the Kafka Producer. If delivery fails, message is dispatched to fallback appenders. Blocks if producer's send buffer is full, unless producerConfig `block.on.buffer.full=false` is set.
Note: Does not prevent blocking by Kafka metadata exchange during broker outages. Can be mitigated by wrapping with Logback's AsyncAppender or Logstash's LoggingEventAsyncDisruptorAppender.
Strategy: BlockingDeliveryStrategy
Description: Blocks each calling thread until the log message is actually delivered. Discouraged due to huge negative impact on throughput.
Warning: Should not be used with producerConfig `linger.ms`.
```
--------------------------------
### Supported Encoders for Kafka Appender Serialization
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Explains that the Logback Kafka Appender supports any `ch.qos.logback.core.encoder.Encoder` for serialization, allowing flexibility with various Logback and Logstash encoders.
```APIDOC
Supported Interface: ch.qos.logback.core.encoder.Encoder
Purpose: Used for encoding ILoggingEvent or IAccessEvent for serialization.
Examples:
- logback PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)
- logstash-logback-encoder's LogstashEncoder
```
--------------------------------
### Override Kafka Producer Configuration
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Explains how to override default Kafka producer configurations within the Logback Kafka Appender using `` elements, allowing fine-tuning of producer behavior.
```APIDOC
Configuration Element: producerConfig
Purpose: Overrides known Kafka producer configurations.
Format: Name=Value
Mandatory Config: boostrap.servers
Examples: batch.size, compression.type, linger.ms
```
--------------------------------
### Define Custom Logback Encoder for Kafka Appender
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Illustrates the basic structure for creating a custom Logback encoder. This encoder can be used with the logback-kafka-appender to serialize log events into custom formats like BSON or Avro, allowing for smaller message sizes and improved performance on both the producing and consuming sides.
```Java
public class MyEncoder extends ch.qos.logback.core.encoder.Encoder {/*..*/}
```
--------------------------------
### Configure Fallback Appenders for Kafka Appender
Source: https://github.com/danielwegener/logback-kafka-appender/blob/master/README.md
Describes how to configure fallback appenders for the Logback Kafka Appender, ensuring messages that cannot be delivered to Kafka are redirected to other appenders.
```APIDOC
Configuration Element: appender-ref
Parent: KafkaAppender
Purpose: Specifies a fallback appender for messages that cannot be published to Kafka.
Example:
Note: Fallback appenders should be fast as they reuse the Kafka producer's IO thread.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.