我知道这个问题一直出现,但是我完全被困住了。
我正在尝试使用Log4j2编写一个KafkaStreams应用程序日志记录,并且收到有关没有附加程序的Log4j(版本1)警告:
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
标准答案是在pom文件中添加一个排除项,但我没有这样做。
它变得更加奇怪,因为即使警告可能提示common-beanutils,导致控制台输出错误的行也是如此:
final Map<String, String> serdeConfig = Collections.singletonMap(
AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
ApplicationConfiguration.SCHEMA_REGISTRY_HOSTS);
我花了一整天的时间,似乎根本没有取得任何进展。
今天之后,我的pom文件杂乱无章,我的依存关系看起来像这样。
<dependencies>
<!--Configuration Dependency for importing properties file-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.2</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Dependency used for Apache commons configuration2-->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<!--Excluded in Map-->
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Log4j2 Dependency for logging-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<!--Required for Log4j2 Dependency for logging-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<!--Used for Object Json Serialization and Deserialization-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<!--Sumo Logic Dependency for Log4j2 logging-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<!--Excluded in Map-->
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Confluent Platform Dependency for streams avro serializer-->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-streams-avro-serde</artifactId>
<version>3.3.0</version>
<!--Required due to SLF4j dependency conflict-->
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<!--Excluded in Map-->
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Confluent Platform Dependency for avro serializer-->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>3.3.0</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Confluent Platform Dependency for schema registry-->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-client</artifactId>
<version>3.3.0</version>
<!--Required due to SLF4j dependency conflict-->
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--Kafka API Client Dependency-->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>1.1.0</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Kafka Streams API Client Dependency-->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>1.1.0</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Avro Serialization Dependency-->
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.8.2</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Avro pojo class generation Dependency-->
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.2</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Avro Serialization Dependency-->
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-tools</artifactId>
<version>1.8.2</version>
<!--Excluded in Map-->
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
并且我已经从当前的依赖关系图中排除了与slf4j相关的任何内容,甚至没有进行日志记录:
我的应用程序日志记录正在按预期方式工作(Console和RolingFileAppender),但我似乎无法消除这种顽固的小警告。
感谢大家在这里阅读我的小书;尤其是如果您有任何建议!
答案 0 :(得分:0)
最终我从上面的评论中选择了选项2。
这样做的原因是,最后,使日志消息最小化并在生产环境中通过源代码管理中的其他文件将其清除似乎更为重要。另外,单独的log4j配置文件的第二个选项使我可以轻松地从依赖项中轻松打开其他调试详细信息(如果我需要它们,例如我的KStreams应用程序似乎无法按预期运行并且很困惑)。 >
具体来说,我实际上创建了两个版本的log4j配置,以便与其他配置/属性一样,本地和(令牌化)发行版具有不同的配置:
$ ls src/main/resources/*/*.xml
src/main/resources/local/log4j.xml* src/main/resources/release/log4j.xml*
src/main/resources/local/log4j2.xml* src/main/resources/release/log4j2.xml*
然后,我正常设置log4j.xml,但默认情况下将根记录器级别设置为off,因此除非更改并使其看起来像这样,否则它将使日志静音:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false">
<appender name="MyConsoleAppender" 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="MyRollingFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="true" />
<param name="maxFileSize" value="100MB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="c:\\Logs\\KStreamsApp\\Dependencies\\KStreamsAppDependencies.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>
<root>
<level value="Off" />
<appender-ref ref="MyConsoleAppender" />
<appender-ref ref="MyRollingFileAppender" />
</root>
</log4j:configuration>