Kafka Streams 忽略 log4j.properties 文件
Kafka Streams ignores log4j.properties file
我正在尝试更改 Kafka Streams 2.7.1 中的日志记录样式,但没有看到任何反应。
项目结构:
log4j.properties的内容:
log4j.rootLogger=DEBUG, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=---------%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n
在 pom.xml 我添加了下一个部门:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
但是应用程序的日志消息与模式不匹配(开头没有破折号):
654 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
654 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
729 [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] WARN org.apache.kafka.clients.NetworkClient - [Consumer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-consumer, groupId=streams-wordcount] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
729 [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] WARN org.apache.kafka.clients.NetworkClient - [Consumer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-consumer, groupId=streams-wordcount] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
741 [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] INFO org.apache.kafka.streams.processor.internals.StreamThread - stream-thread [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] Processed 0 total records, ran 0 punctuators, and committed 0 total tasks since the last update
754 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
754 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
为什么不起作用?
正如@OneCricketeer 在评论中提到的那样——我不得不修复一些依赖项的错误。而且我不得不添加以 slf4j 替换 slf4j-log4j12 才能使用 log4j.property 文件。
作为最终解决方案,我在 pom.xml:
中有此依赖项
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
我正在尝试更改 Kafka Streams 2.7.1 中的日志记录样式,但没有看到任何反应。
项目结构:
log4j.properties的内容:
log4j.rootLogger=DEBUG, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=---------%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n
在 pom.xml 我添加了下一个部门:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
但是应用程序的日志消息与模式不匹配(开头没有破折号):
654 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
654 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
729 [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] WARN org.apache.kafka.clients.NetworkClient - [Consumer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-consumer, groupId=streams-wordcount] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
729 [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] WARN org.apache.kafka.clients.NetworkClient - [Consumer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-consumer, groupId=streams-wordcount] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
741 [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] INFO org.apache.kafka.streams.processor.internals.StreamThread - stream-thread [streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1] Processed 0 total records, ran 0 punctuators, and committed 0 total tasks since the last update
754 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
754 [kafka-producer-network-thread | streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=streams-wordcount-87c688dc-7ade-4b4b-bd06-1187ffa4755a-StreamThread-1-producer] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
为什么不起作用?
正如@OneCricketeer 在评论中提到的那样——我不得不修复一些依赖项的错误。而且我不得不添加以 slf4j 替换 slf4j-log4j12 才能使用 log4j.property 文件。 作为最终解决方案,我在 pom.xml:
中有此依赖项 <dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>