zoukankan      html  css  js  c++  java
  • logback-kafka-appender

    logback 日志写入kafka队列

     

    logback-kafka-appender

    Logback incompatibility Warning

    Due to a bug in logback-core (LOGBACK-1158), logback-kafka-appender does not work with logback 1.1.7. This bug will be fixed in the upcoming logback 1.1.8. Until 1.1.8 is released, we recommend to use logback 1.1.6.

    Full configuration example

    Add logback-kafka-appender and logback-classic as library dependencies to your project.

    [maven pom.xml]
    <dependency>
        <groupId>com.github.danielwegener</groupId>
        <artifactId>logback-kafka-appender</artifactId>
        <version>0.1.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.2</version>
        <scope>runtime</scope>
    </dependency>
    // [build.sbt]
    libraryDependencies += "com.github.danielwegener" % "logback-kafka-appender" % "0.1.0"
    libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.7"

    This is an example logback.xml that uses a common PatternLayout to encode a log message as a string.

    [src/main/resources/logback.xml]
    <configuration>
    
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>
    
        <!-- This is the kafkaAppender -->
        <appender name="kafkaAppender" class="com.github.danielwegener.logback.kafka.KafkaAppender">
                <!-- This is the default encoder that encodes every log message to an utf8-encoded string  -->
                <encoder class="com.github.danielwegener.logback.kafka.encoding.LayoutKafkaMessageEncoder">
                    <layout class="ch.qos.logback.classic.PatternLayout">
                        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
                    </layout>
                </encoder>
                <topic>logs</topic>
                <keyingStrategy class="com.github.danielwegener.logback.kafka.keying.RoundRobinKeyingStrategy" />
                <deliveryStrategy class="com.github.danielwegener.logback.kafka.delivery.AsynchronousDeliveryStrategy" />
    
                <!-- each <producerConfig> translates to regular kafka-client config (format: key=value) -->
                <!-- producer configs are documented here: https://kafka.apache.org/documentation.html#newproducerconfigs -->
                <!-- bootstrap.servers is the only mandatory producerConfig -->
                <producerConfig>bootstrap.servers=localhost:9092</producerConfig>
    
                <!-- this is the fallback appender if kafka is not available. -->
                <appender-ref ref="STDOUT" />
            </appender>
    
        <root level="info">
            <appender-ref ref="kafkaAppender" />
        </root>
    </configuration>
  • 相关阅读:
    OI回忆录——一个过气OIer的制杖历程
    博客园美化手记——CSS javascript html
    ProjectEuler && Rosecode && Mathmash做题记录
    算法竞赛推荐
    2020智算之道复赛E 树数数
    牛客编程巅峰赛S1第9场
    c++小学期大作业攻略(五)基于QSS的样式美化
    c++小学期大作业攻略(四)任务系统+站内信
    c++小学期大作业攻略(三)用户系统
    c++小学期大作业攻略(零)建议+代码结构(持续更新)
  • 原文地址:https://www.cnblogs.com/adolfmc/p/7348240.html
Copyright © 2011-2022 走看看