收到在添加Pulsar appender时出现log4j2的"未找到appender"错误。

huangapple go评论109阅读模式
英文:

Receiving "No appender found" error for log4j2 when adding Pulsar appender

问题

我正在处理一个复杂的应用程序,该应用程序使用了Ignite版本的log4j2。它运行得很好,但是当我尝试添加一个Pulsar appender 时,它会抛出一个错误:

log4j:WARN 无法找到记录器的附加器(org.apache.pulsar.shade.io.netty.util.internal.logging.InternalLoggerFactory)。
log4j:WARN 请正确初始化log4j系统。
log4j:WARN 详见http://logging.apache.org/log4j/1.2/faq.html#noconfig获取更多信息。

我无法真正弄清楚为什么它在寻找log4j2.xml文件时失败,因为在没有Pulsar appender的情况下,它运行得很好,所以它一定在类路径上。我猜想这可能是ignite-log4j2依赖和pulsar-log4j2-appender依赖之间的冲突。

这是我的 pom.xml 配置:

<dependencies>
    <!-- 其他依赖... -->
    <!-- Pulsar logging -->
    <dependency>
        <groupId>org.apache.pulsar</groupId>
        <artifactId>pulsar-log4j2-appender</artifactId>
        <version>2.6.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-slf4j-impl</artifactId>
            </exclusion>
            <!-- 其他排除项... -->
        </exclusions>
    </dependency>
</dependencies>

以及我的 log4j2.xml 配置:

<Configuration monitorInterval="60">
    <Appenders>
        <!-- 其他 appender 配置... -->
        <Pulsar name="PULSAR" serviceUrl="pulsar://172.21.11.82:6650" topic="json_persistor"  avoidRecursive="false">
            <PatternLayout pattern="%msg%n"/>
        </Pulsar>
    </Appenders>
    
    <Loggers>
        <!-- 其他 logger 配置... -->
        <Logger name="com.coinflex.common.persistor.JsonObjectPersistor" level="INFO" additivity="false">
            <AppenderRef ref="PULSAR"/>
        </Logger>
        <!-- 其他 logger 配置... -->
    </Loggers>
</Configuration>
英文:

I'm working on a complex application that uses an Ignite version of log4j2. It works perfectly fine, but when I try to add a Pulsar appender it throws an error:

log4j:WARN No appenders could be found for logger (org.apache.pulsar.shade.io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I can't really figure out why it's failing to find the log4j2.xml file because without the Pulsar appender it works fine, so it must be on the classpath. I'm guessing it must be a conflict with the ignite-log4j2 dependency and pulsar-log4j2-appender dependency.

This is what my pom.xml looks like:

   &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
            &lt;artifactId&gt;ignite-spring&lt;/artifactId&gt;
            &lt;version&gt;${ignite.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
            &lt;artifactId&gt;ignite-zookeeper&lt;/artifactId&gt;
            &lt;version&gt;${ignite.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
            &lt;artifactId&gt;ignite-urideploy&lt;/artifactId&gt;
            &lt;version&gt;${ignite.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
            &lt;artifactId&gt;ignite-log4j2&lt;/artifactId&gt;
            &lt;version&gt;${ignite.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
            &lt;artifactId&gt;gson&lt;/artifactId&gt;
            &lt;version&gt;2.8.6&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.pulsar&lt;/groupId&gt;
            &lt;artifactId&gt;pulsar-client&lt;/artifactId&gt;
            &lt;version&gt;${pulsar.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.java-websocket&lt;/groupId&gt;
            &lt;artifactId&gt;Java-WebSocket&lt;/artifactId&gt;
            &lt;version&gt;1.3.8&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
        &lt;/dependency&gt;

        &lt;!-- Pulsar logging --&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.pulsar&lt;/groupId&gt;
            &lt;artifactId&gt;pulsar-log4j2-appender&lt;/artifactId&gt;
            &lt;version&gt;2.6.0&lt;/version&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                    &lt;artifactId&gt;log4j-slf4j-impl&lt;/artifactId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;org.apache.pulsar&lt;/groupId&gt;
                    &lt;artifactId&gt;pulsar-client&lt;/artifactId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                    &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                    &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;

And my log4j2.xml:

&lt;Configuration monitorInterval=&quot;60&quot;&gt;
    &lt;Appenders&gt;
        &lt;Console name=&quot;CONSOLE&quot; target=&quot;SYSTEM_OUT&quot;&gt;
            &lt;PatternLayout pattern=&quot;%d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n&quot;/&gt;
            &lt;ThresholdFilter level=&quot;ERROR&quot; onMatch=&quot;DENY&quot; onMismatch=&quot;ACCEPT&quot;/&gt;
        &lt;/Console&gt;

        &lt;Console name=&quot;CONSOLE_ERR&quot; target=&quot;SYSTEM_ERR&quot;&gt;
            &lt;PatternLayout pattern=&quot;[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n&quot;/&gt;
        &lt;/Console&gt;

        &lt;Routing name=&quot;FILE&quot;&gt;
            &lt;Routes pattern=&quot;$${sys:nodeId}&quot;&gt;
                &lt;Route&gt;
                    &lt;RollingFile name=&quot;Rolling-${sys:nodeId}&quot; fileName=&quot;ignite/work/log/ignite-${sys:nodeId}.log&quot;
                                 filePattern=&quot;ignite/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz&quot;&gt;
                        &lt;PatternLayout pattern=&quot;[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n&quot;/&gt;
                        &lt;Policies&gt;
                            &lt;TimeBasedTriggeringPolicy interval=&quot;6&quot; modulate=&quot;true&quot; /&gt;
                            &lt;SizeBasedTriggeringPolicy size=&quot;10 MB&quot; /&gt;
                        &lt;/Policies&gt;
                    &lt;/RollingFile&gt;
                &lt;/Route&gt;
            &lt;/Routes&gt;
        &lt;/Routing&gt;
        &lt;Pulsar name=&quot;PULSAR&quot; serviceUrl=&quot;pulsar://172.21.11.82:6650&quot; topic=&quot;json_persistor&quot;  avoidRecursive=&quot;false&quot;&gt;
            &lt;PatternLayout pattern=&quot;%msg%n&quot;/&gt;
        &lt;/Pulsar&gt;
    &lt;/Appenders&gt;

    &lt;Loggers&gt;
        &lt;Logger name=&quot;org.apache.pulsar&quot; level=&quot;INFO&quot;/&gt; &lt;!-- to avoid recursive logging --&gt;
        &lt;Logger name=&quot;com.coinflex.common.persistor.JsonObjectPersistor&quot; level=&quot;INFO&quot; additivity=&quot;false&quot;&gt;
            &lt;AppenderRef ref=&quot;PULSAR&quot;/&gt;
        &lt;/Logger&gt;

        &lt;Logger name=&quot;org.apache.ignite&quot; level=&quot;ERROR&quot;/&gt;
        &lt;Logger name=&quot;org.springframework&quot; level=&quot;WARN&quot;/&gt;
        &lt;Logger name=&quot;org.eclipse.jetty&quot; level=&quot;WARN&quot;/&gt;
        &lt;Logger name=&quot;org.eclipse.jetty.util.log&quot; level=&quot;ERROR&quot;/&gt;
        &lt;Logger name=&quot;org.eclipse.jetty.util.component&quot; level=&quot;ERROR&quot;/&gt;
        &lt;Logger name=&quot;com.amazonaws&quot; level=&quot;WARN&quot;/&gt;

        &lt;Root level=&quot;INFO&quot;&gt;
            &lt;AppenderRef ref=&quot;CONSOLE&quot; level=&quot;INFO&quot;/&gt;
            &lt;AppenderRef ref=&quot;CONSOLE_ERR&quot; level=&quot;ERROR&quot;/&gt;
            &lt;AppenderRef ref=&quot;FILE&quot; level=&quot;DEBUG&quot;/&gt;
        &lt;/Root&gt;
    &lt;/Loggers&gt;
&lt;/Configuration&gt;

答案1

得分: 2

收到,以下是您要翻译的内容:

得到的错误消息来自于 Log4J 1。这表明未使用 Log4J 2,这就解释了为什么找不到 pulsar appender。

如果您想使用 Log4J 2,您需要重新检查您的依赖项。

这也表明它未使用您的日志配置。

英文:

The error message you are getting is coming from Log4J 1. This indicates Log4J 2 isn’t being used, which would explain why it can’t find the pulsar appender.

If you want to use Log4J 2 you need to re-examine your dependencies.

This also indicates it isn’t using your logging configuration.

huangapple
  • 本文由 发表于 2020年7月24日 14:09:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63067809.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定