记录配置不适用于Akka

时间:2019-04-27 11:54:19

标签: scala logging apache-kafka akka slf4j

我在使用Akka登录时遇到配置问题。在我的STDOUT中,它没有隐藏它们的DEBUG消息。在我的控制台中,我看到以下内容:

12:45:27.790 [example-akka.kafka.default-dispatcher-18] DEBUG org.apache.kafka.clients.consumer.KafkaConsumer - [Consumer clientId=consumer-1, groupId=group1] Resuming partitions [test-topic-0]
12:45:27.823 [example-akka.kafka.default-dispatcher-18] DEBUG org.apache.kafka.clients.FetchSessionHandler - [Consumer clientId=consumer-1, groupId=group1] Node 1001 sent an incremental fetch response for session 1829476633 with 0 response partition(s), 1 implied partition(s)

所以我需要停止查看DEBUG消息。我这样进行记录:

akka {

  # Loggers to register at boot time (akka.event.Logging$DefaultLogger logs
  # to STDOUT)
  loggers = ["akka.event.slf4j.Slf4jLogger"]

  # Log level used by the configured loggers (see "loggers") as soon
  # as they have been started; before that, see "stdout-loglevel"
  # Options: OFF, ERROR, WARNING, INFO, DEBUG
  loglevel = "INFO"

  # Log level for the very basic logger activated during ActorSystem startup.
  # This logger prints the log messages to stdout (System.out).
  # Options: OFF, ERROR, WARNING, INFO, DEBUG
  stdout-loglevel = "INFO"

}

在我的logback.xml中,我正在编写:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{ISO8601} level=[%level] marker=[%marker] logger=[%logger] akkaSource=[%X{akkaSource}]
                sourceActorSystem=[%X{sourceActorSystem}] sourceThread=[%X{sourceThread}] mdc=[ticket-#%X{ticketNumber}:
                %X{ticketDesc}] - msg=[%msg]%n----%n
            </pattern>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>

</configuration>

为什么不停止调试消息?

我的项目结构

src-> main-> scala(这里是我在Scala中的源文件) src-> main-> scala->资源(这里是我的lokback.xml和appliction.conf)

2 个答案:

答案 0 :(得分:1)

可以将日志级别配置为at package level,例如,将以下内容添加到logback.xml

<logger name="org.apache.kafka" level="INFO"/>

INFO软件包中所有组件的日志级别设置为org.apache.kafka,这将停止DEBUG消息。

答案 1 :(得分:1)

您的sbt项目结构不正确。这应该是正确的结构:

src/
  main/
    resources/
       <files to include in main jar here>
    scala/
       <main Scala sources>
    java/
       <main Java sources>
  test/
    resources
       <files to include in test jar here>
    scala/
       <test Scala sources>
    java/
       <test Java sources>

然后,您还需要遵循@Mario的建议以及在包级别调整日志记录。