默认情况下,如果项目中集成了Logback等日志框架,在执行main方法时通过其进行日志打印,那么默认的日志级别是debug的。
22:03:55.386 [main] DEBUG org.apache.kafka.clients.consumer.internals.OffsetsForLeaderEpochClient - [Consumer clientId=consumer-kafka-consumer-demo-1, groupId=kafka-consumer-demo] Handling OffsetsForLeaderEpoch response for kafka-0. Got offset 267 for epoch 0
22:03:55.386 [main] DEBUG org.apache.kafka.clients.consumer.internals.OffsetsForLeaderEpochClient - [Consumer clientId=consumer-kafka-consumer-demo-1, groupId=kafka-consumer-demo] Handling OffsetsForLeaderEpoch response for kafka-1. Got offset 194 for epoch 0
此时,如果是http请求,甚至可以把请求的具体报文信息都打印出来,特别是三方框架的。为了不影响查看正常的日志,可以将main方法的日志级别进行调整。
此时,配置Logback的logback.xml文件或配置项目的日志输出(比如spring boot)是无效的,只需在类静态代码块中添加以下代码即可。
static {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
List<ch.qos.logback.classic.Logger> loggerList = loggerContext.getLoggerList();
loggerList.forEach(logger -> {
logger.setLevel(Level.INFO);
});
}
此时,再执行main方法,打印的日志级别便是info级别的了:
22:02:16.274 [main] INFO org.apache.kafka.clients.consumer.internals.ConsumerCoordinator - [Consumer clientId=consumer-kafka-consumer-demo-1, groupId=kafka-consumer-demo] Setting offset for partition kafka-0 to the committed offset FetchPosition{offset=266, offsetEpoch=Optional[0], currentLeader=LeaderAndEpoch{leader=Optional[8.122.88.88:9992 (id: 0 rack: null)], epoch=0}}
22:02:16.275 [main] INFO org.apache.kafka.clients.consumer.internals.ConsumerCoordinator - [Consumer clientId=consumer-kafka-consumer-demo-1, groupId=kafka-consumer-demo] Setting offset for partition kafka-1 to the committed offset FetchPosition{offset=194, offsetEpoch=Optional[0], currentLeader=LeaderAndEpoch{leader=Optional[8.122.88.88:9992 (id: 0 rack: null)], epoch=0}}
标签:demo,级别,kafka,offset,日志,main,consumer From: https://www.cnblogs.com/huangdh/p/16882179.html