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

337 views Asked by At

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:

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

        <!-- 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>
                <exclusion>
                    <groupId>org.apache.pulsar</groupId>
                    <artifactId>pulsar-client</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

And my log4j2.xml:

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

        <Console name="CONSOLE_ERR" target="SYSTEM_ERR">
            <PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
        </Console>

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

    <Loggers>
        <Logger name="org.apache.pulsar" level="INFO"/> <!-- to avoid recursive logging -->
        <Logger name="com.coinflex.common.persistor.JsonObjectPersistor" level="INFO" additivity="false">
            <AppenderRef ref="PULSAR"/>
        </Logger>

        <Logger name="org.apache.ignite" level="ERROR"/>
        <Logger name="org.springframework" level="WARN"/>
        <Logger name="org.eclipse.jetty" level="WARN"/>
        <Logger name="org.eclipse.jetty.util.log" level="ERROR"/>
        <Logger name="org.eclipse.jetty.util.component" level="ERROR"/>
        <Logger name="com.amazonaws" level="WARN"/>

        <Root level="INFO">
            <AppenderRef ref="CONSOLE" level="INFO"/>
            <AppenderRef ref="CONSOLE_ERR" level="ERROR"/>
            <AppenderRef ref="FILE" level="DEBUG"/>
        </Root>
    </Loggers>
</Configuration>
1

There are 1 answers

0
rgoers On BEST ANSWER

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.