如何使用log4j在日志中打印spring kafka配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用log4j在日志中打印spring kafka配置相关的知识,希望对你有一定的参考价值。

有没有办法使用log4j记录日志中的所有spring-kafka配置?我尝试在我的应用程序log4j2.yml中使用以下记录器配置,我可以看到所有信息和调试日志,但不能看到配置。 - name:org.springframework.kafka additivity:false level:info / debug AppenderRef: - ref:SOME_APPENDER提前感谢您的帮助。

答案

我认为你真的只需要担心应用于Apache Kafka客户端的属性。这也将涵盖Spring Kafka配置。为此,您只需要为INFO类别配置org.apache.kafka.clients

这是我的一个测试的日志:

16:55:20.616 INFO  [main][org.apache.kafka.clients.consumer.ConsumerConfig] ConsumerConfig values: 
    auto.commit.interval.ms = 10
    auto.offset.reset = earliest
    bootstrap.servers = [127.0.0.1:56505]
    check.crcs = true
    client.id = 
    connections.max.idle.ms = 540000
    enable.auto.commit = false
    exclude.internal.topics = true
    fetch.max.bytes = 52428800
    fetch.max.wait.ms = 500
    fetch.min.bytes = 1
    group.id = blc
    heartbeat.interval.ms = 3000
    interceptor.classes = null
    internal.leave.group.on.close = true
    isolation.level = read_uncommitted
    key.deserializer = class org.apache.kafka.common.serialization.IntegerDeserializer
    max.partition.fetch.bytes = 1048576
    max.poll.interval.ms = 300000
    max.poll.records = 500
    metadata.max.age.ms = 300000
    metric.reporters = []
    metrics.num.samples = 2
    metrics.recording.level = INFO
    metrics.sample.window.ms = 30000
    partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
    receive.buffer.bytes = 65536
    reconnect.backoff.max.ms = 1000
    reconnect.backoff.ms = 50
    request.timeout.ms = 305000
    retry.backoff.ms = 100
    sasl.jaas.config = null
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    sasl.kerberos.min.time.before.relogin = 60000
    sasl.kerberos.service.name = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    sasl.kerberos.ticket.renew.window.factor = 0.8
    sasl.mechanism = GSSAPI
    security.protocol = PLAINTEXT
    send.buffer.bytes = 131072
    session.timeout.ms = 60000
    ssl.cipher.suites = null
    ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
    ssl.endpoint.identification.algorithm = null
    ssl.key.password = null
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.location = null
    ssl.keystore.password = null
    ssl.keystore.type = JKS
    ssl.protocol = TLS
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.location = null
    ssl.truststore.password = null
    ssl.truststore.type = JKS
    value.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
另一答案

这对我来说很好......

Configutation:
  name: Default

  Properties:
    Property:
      name: log-path
      value: "logs"

  Appenders:

    Console:
      name: Console_Appender
      target: SYSTEM_OUT
      PatternLayout:
        pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"

  Loggers:

      Root:
        level: warn
        AppenderRef:
          - ref: Console_Appender

      Logger:
        - name: org.apache.kafka
          level: info
          AppenderRef:
            - ref: Console_Appender

[INFO ] 2017-12-20 17:00:08.591 [main] ProducerConfig - ProducerConfig values: 
    acks = 1
    batch.size = 16384
    bootstrap.servers = [localhost:9092]
    buffer.memory = 33554432
    ...

以上是关于如何使用log4j在日志中打印spring kafka配置的主要内容,如果未能解决你的问题,请参考以下文章

如何在spring boot中配置log4j写入文件?

如何关闭log4j中配置的spring或者hibernate的日志信息

springboot集成log4j + sql打印日志

spring boot (4) 使用log4 打印日志

logback的使用和logback.xml详解,在Spring项目中使用log打印日志

如何将web应用项目中log4j的日志只打印到独立的文件,不打印在Tomcat的catalina.out?