无法找到appender

时间:2015-08-10 11:11:00

标签: java logging configuration slf4j log4j2

我正在尝试在弹簧网络应用程序中从log4j 1迁移到log4j 2。当我构建它时,我收到以下错误:

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

将以下jar添加到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. 共享记录-1.1.1.jar
  6. Apache的log4j的-额外-1.1.jar
  7. 我的log4j2.xml看起来像:

    <?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>
    

2 个答案:

答案 0 :(得分:4)

您的RollingFile配置需要指定触发翻转的内容。您可以通过添加<Policy>元素来完成此操作。有关详细信息,请参阅RollingFile manual entry

我相信在结束</RollingFile>标记之前添加此代码段应解决问题:

<Policies>
  <TimeBasedTriggeringPolicy />
</Policies>

对于analyticsFileAppender RollingFile appender,您配置了datePattern,您想要说filePattern。以下是固定的配置代码段。

<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>

答案 1 :(得分:0)

首先,删除Async appender,并将AsyncLogger的appender-ref直接指向ProcessorLoggingFile。其次,您必须在AsyncLogger上添加includeLocation =“true”。

除了异步记录器之外还有一个异步appender没有帮助,在这种情况下可能会阻止includeLocation正常工作。

修改 CHECK THIS提出更多帮助。