Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate appender

I am trying to migrate from log4j 1 to log4j 2 in a spring web application. When I build it I get the following error:

2015-08-10 16:26:36,222 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2015-08-10 16:26:36,222 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for builder factory method...
2015-08-10 16:26:36,222 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger. Going to try finding a factory method instead.
2015-08-10 16:26:36,223 DEBUG Still building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for factory method...
2015-08-10 16:26:36,223 DEBUG Found factory method [createLogger]: public static org.apache.logging.log4j.core.config.LoggerConfig org.apache.logging.log4j.core.config.LoggerConfig$RootLogger.createLogger(java.lang.String,org.apache.logging.log4j.Level,java.lang.String,org.apache.logging.log4j.core.config.AppenderRef[],org.apache.logging.log4j.core.config.Property[],org.apache.logging.log4j.core.config.Configuration,org.apache.logging.log4j.core.Filter).
2015-08-10 16:26:36,224 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root with params(name="null", name="INFO", name="null", ={appFileAppender}, ={}, Configuration(/Applications/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml), null)
2015-08-10 16:26:36,225 DEBUG Built Plugin[name=root] OK from factory method.
2015-08-10 16:26:36,225 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for builder factory method...
2015-08-10 16:26:36,227 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggersPlugin. Going to try finding a factory method instead.
2015-08-10 16:26:36,228 DEBUG Still building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for factory method...
2015-08-10 16:26:36,228 DEBUG Found factory method [createLoggers]: public static org.apache.logging.log4j.core.config.Loggers org.apache.logging.log4j.core.config.LoggersPlugin.createLoggers(org.apache.logging.log4j.core.config.LoggerConfig[]).
2015-08-10 16:26:36,229 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers with params(={app, analyticsLogger, dpLogger, trackingPixelLogger, filteredLogsLogger, trackingOffersPurchasingLogger, ifbLogger, trackingOffersUdidLogger, trackingOffersHeadersLogger, apLogger, s3AdminLogger, bookPackLogger, accumulatorLogger, appDownloadLogger, botDetectionLogger, fourGLogger, urlShortenerLogger, TrackingAllLogger, otiHeadersLogger, postpaidErrorTrackingLogger, root})
2015-08-10 16:26:36,230 DEBUG Built Plugin[name=loggers] OK from factory method.
2015-08-10 16:26:36,235 ERROR Unable to locate appender appFileAppender for logger
2015-08-10 16:26:36,237 ERROR No appender named fourGFileAppender was configured

Following jars are added to classpath:

  1. log4j-slf4j-impl-2.3.jar
  2. log4j-core-2.3.jar
  3. log4j-api-2.3.jar
  4. slf4j-api-1.7.12.jar
  5. commons-logging-1.1.1.jar
  6. apache-log4j-extras-1.1.jar

And my log4j2.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">

    <Appenders>

        <RollingFile name="appFileAppender" fileName="/tmp/portal-fe.log"
                     filePattern="/tmp/portal-fe.%d{yyyy-MM-dd}.log.gz">
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss} [%p] | [%t] [%X{requestId}] [%X{x_msisdn}] [%X{x_rat}] [%X{x_forwarded_for}] [%X{circle}] [%C{1}:%L] %m%n"/>
        </RollingFile>


        <RollingFile name="analyticsFileAppender" fileName="/tmp/ops_bc_log"
                     datePattern="'-'yyyyMMdd">
            <PatternLayout
                    pattern="%d{yyyy/MM/dd HH:mm:ss} %m%n"/>
        </RollingFile>

        <Async name="ASYNC">
            <AppenderRef ref="appFileAppender"/>
        </Async>

        <Async name="ASYNC_2">
            <AppenderRef ref="analyticsFileAppender"/>
        </Async>

    </Appenders>

    <Loggers>

        <Logger name="app" level="debug">
            <AppenderRef ref="ASYNC"/>
        </Logger>

        <Logger name="analyticsLogger" level="info">
            <AppenderRef ref="ASYNC_2"/>
        </Logger>

        <Root level="info">
            <AppenderRef ref="appFileAppender"/>
        </Root>
    </Loggers>

</Configuration>
like image 376
Antara Roy Avatar asked Aug 10 '15 11:08

Antara Roy


1 Answers

Your RollingFile configuration needs to specify what triggers a rollover. You do this by adding a <Policy> element. See the RollingFile manual entry for details.

I believe adding this snippet before the closing </RollingFile> tag should fix the issue:

<Policies>
  <TimeBasedTriggeringPolicy />
</Policies>

For the analyticsFileAppender RollingFile appender you configured a datePattern where you meant to say filePattern. Below is the fixed config snippet.

<RollingFile name="analyticsFileAppender" fileName="/tmp/ops_bc_log"
             filePattern="'-'yyyyMMdd">
  <PatternLayout pattern="%d{yyyy/MM/dd HH:mm:ss} %m%n"/>
  <Policies>
    <TimeBasedTriggeringPolicy />
  </Policies>
</RollingFile>
like image 161
Remko Popma Avatar answered Nov 01 '22 15:11

Remko Popma