spring kafka -手动设置用户日志级别(spring 5).



我们最近正在做spring项目,并与spring-kafka集成。在我们能够正确地生成和消费消息的地方,它正在按预期工作。

但是当我们将项目移动到PROD时,我们得到了DEBUG级别的日志语句和不堪重负的语句数量。我们正在尝试将日志级别设置为WARN或ERROR专门用于Kafka日志。

在进程中我们添加了logback.xml(添加在主/资源中)遵循下面的文章,但没有运气,也尝试了我们在互联网上遇到的其他解决方案。(添加log4j。属性log4j2.xml)

  • https://www.baeldung.com/logback

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration name="default">
<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>
<logger name="org.apache.kafka"                 level="error" />
<logger name="org.apache.kafka.common.metrics"  level="error"/>
<logger name="org.apache.kafka.clients"         level="error"/>
<logger name="org.apache.kafka.clients.consumer.internals"          level="error"/>
<logger name="org.apache.kafka.clients.consumer.internals.Fetcher"  level="error"/>

<root level="error" name="org.apache.kafka" additivity="false">
<appender-ref ref="STDOUT" />
</root> 

</configuration>

示例日志:

[org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] INFO org.apache.kafka.clients.Metadata - [Consumer clientId=client-01, groupId=publisher] Cluster ID: Udhjf-fdbfds
[org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] INFO org.apache.kafka.clients.consumer.internals.AbstractCoordinator - [Consumer clientId=client-01, groupId=publisher] Discovered group coordinator 127.....0 (id: 65654654654 rack: null)
[org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] INFO org.apache.kafka.clients.consumer.internals.AbstractCoordinator -  [Consumer clientId=client-01, groupId=publisher] (Re-)joining group
[WebSphere non-WLM Dispatch Thread t=008abcf0] WARN org.apache.kafka.clients.consumer.ConsumerConfig - The configuration 'schema.registry.url' was supplied but isn't a known config.
[WebSphere non-WLM Dispatch Thread t=008abcf0] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version: 2.7.1
[WebSphere non-WLM Dispatch Thread t=008abcf0] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: 616tyu85d0d567566

任何人遇到类似的情况或任何线索将是非常有用的。提前感谢。:)

回答晚了,但可能对某人有帮助。

我们在相同的logback.xml中做了一些更改文件,还添加了log4j2.xml以使其在我们的应用程序中工作。以下是两个文件的修改,请尝试一下。

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration name="default">
<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>

<logger name="org.apache.log4j.xml"            level="error"/>
<logger name="org.apache.http"                 level="error" />
<logger name="org.apache.http.wire"            level="error"/>
<logger name="org.apache.commons.httpclient"   level="error"/>

<logger name="org.springframework" level="error">
<appender-ref ref="STDOUT" />
</logger> 

<logger name="org.springframework.kafka" level="error" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<logger name="org.apache.kafka" level="info" additivity="false">
<appender-ref ref="STDOUT" />
</logger>

<root level="error">
<appender-ref ref="STDOUT" />
</root> 
</configuration>

log4j2.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">  
<log4j:configuratio xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">  
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">  
<layout class="org.apache.log4j.PatternLayout">  
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />  
</layout>  
</appender>  
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">  
<param name="append" value="true" />  
<param name="maxFileSize" value="10MB" />  
<param name="maxBackupIndex" value="10" />  
<param name="file" value="${catalina.home}/logs/myStruts1App.log" />  
<layout class="org.apache.log4j.PatternLayout">  
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />  
</layout>  
</appender>  
<logger name="org.springframework">
<level value="error" />
</logger>
<logger name="org.springframework.kafka">
<level value="error" />
</logger>
<logger name="org.apache.http">
<level value="warn" />
</logger>

<logger name="org.apache.http.wire">
<level value="warn" />
</logger>
<logger name="org.apache.commons.httpclient">
<level value="warn" />
</logger>
<logger name="org.apache.kafka">
<level value="error" />
</logger>
<root>  
<!-- DEBUG level for all other loggers -->
<priority value="debug" />  
<appender-ref ref="consoleAppender" />  
<appender-ref ref="fileAppender" />  
</root>  
</log4j:configuration>  

我们可以在这里看到一些与加法相关的变化,试着查看下面的文章来了解更多关于它的信息。

https://newsbasis.com/what-is-additivity-in-logback/
  • Logback日志记录器记录两次

相关内容

  • 没有找到相关文章

最新更新