我们无法使用 log4j2 让 flumeappender 工作。但是,使用 log4j.properties 配置文件,而不是通过 log4j2.xml。我们得到的错误是:Error processing element Flume: CLASS_NOT_FOUND
以下是我的 Maven 依赖项:
<dependencies>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-sdk</artifactId>
<version>1.5.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.flume.flume-ng-clients</groupId>
<artifactId>flume-ng-log4jappender</artifactId>
<version>1.5.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
以下是我的 log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" name="CE" packages="net.ahm.ce.server">
<Appenders>
<Flume name="eventLogger" compress="true" type="Embedded">
<Agent host="192.168.4.16" port="41414" />
<RFC5424Layout enterpriseNumber="18060" includeMDC="true"
appName="CE" />
</Flume>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="eventLogger" />
</Root>
</Loggers>
</Configuration>
启动时的日志:
2014-09-17 10:41:27,339 DEBUG Starting configuration XmlConfiguration[location=C:\dev\AHM\FlumePOC\server\target\classes\log4j2.xml]
2014-09-17 10:41:27,339 DEBUG Generated plugins in 0.001350 seconds, packages: [net.ahm.ce.server], preload: false.
2014-09-17 10:41:27,339 DEBUG Found Plugin Map at jar:file:/C:/Users/droy/.m2/repository/org/apache/logging/log4j/log4j-core/2.0.2/log4j-core-2.0.2.jar!/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
2014-09-17 10:41:27,588 DEBUG Generated plugins in 0.243478 seconds, packages: [net.ahm.ce.server, org.apache.logging.log4j.core], preload: true.
2014-09-17 10:41:27,604 ERROR Error processing element Flume: CLASS_NOT_FOUND
2014-09-17 10:41:27,697 DEBUG Generated plugins in 0.100369 seconds, packages: [net.ahm.ce.server, org.apache.logging.log4j.core], preload: false.
2014-09-17 10:41:27,697 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. Searching for builder factory method...
2014-09-17 10:41:27,697 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppendersPlugin. Going to try finding a factory method instead.
2014-09-17 10:41:27,697 DEBUG Still building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. Searching for factory method...
2014-09-17 10:41:27,697 DEBUG Found factory method [createAppenders]: public static java.util.concurrent.ConcurrentMap org.apache.logging.log4j.core.config.AppendersPlugin.createAppenders(org.apache.logging.log4j.core.Appender[]).
2014-09-17 10:41:27,697 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.AppendersPlugin for element Appenders with params(={})
2014-09-17 10:41:27,697 DEBUG Built Plugin[name=appenders] OK from factory method.
2014-09-17 10:41:27,697 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for builder factory method...
2014-09-17 10:41:27,697 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppenderRef. Going to try finding a factory method instead.
2014-09-17 10:41:27,697 DEBUG Still building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for factory method...
2014-09-17 10:41:27,697 DEBUG Found factory method [createAppenderRef]: public static org.apache.logging.log4j.core.config.AppenderRef org.apache.logging.log4j.core.config.AppenderRef.createAppenderRef(java.lang.String,org.apache.logging.log4j.Level,org.apache.logging.log4j.core.Filter).
2014-09-17 10:41:27,713 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(ref="eventLogger", level="null", null)
2014-09-17 10:41:27,713 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2014-09-17 10:41:27,713 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for builder factory method...
2014-09-17 10:41:27,713 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger. Going to try finding a factory method instead.
2014-09-17 10:41:27,713 DEBUG Still building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for factory method...
2014-09-17 10:41:27,713 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).
2014-09-17 10:41:27,713 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root with params(additivity="null", level="DEBUG", includeLocation="null", ={eventLogger}, ={}, Configuration(CE), null)
2014-09-17 10:41:27,713 DEBUG Built Plugin[name=root] OK from factory method.
2014-09-17 10:41:27,713 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for builder factory method...
2014-09-17 10:41:27,713 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggersPlugin. Going to try finding a factory method instead.
2014-09-17 10:41:27,713 DEBUG Still building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for factory method...
2014-09-17 10:41:27,713 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[]).
2014-09-17 10:41:27,713 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers with params(={root})
2014-09-17 10:41:27,713 DEBUG Built Plugin[name=loggers] OK from factory method.
2014-09-17 10:41:27,713 ERROR Unable to locate appender eventLogger for logger