我无法初始化log4j catalina log appender - 你知道我错过了什么吗?我知道这是一个基本问题,但我仍然坚持这一点。我为catalina记录器添加了一个org.apache.log4j.net.SyslogAppender定义,但没有运气。
log4j:警告没有找到记录器的附加程序(org.apache.catalina.startup.Catalina) log4j:WARN请正确初始化log4j系统
据我所知,我正在使用-log4j.xml初始化log4j系统 - 我做错了什么?我再次知道这是一个基本问题。这是我的/src/main/resources/log4j.xml
文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender class="org.apache.log4j.ConsoleAppender" name="stdout">
<layout class="com.us.platform.thing.log.SyslogPatternLayout">
<param value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %t %-5p %m%n" name="ConversionPattern"/>
</layout>
<filter class="com.us.platform.thing.log.filter.DynamicLevelFilter">
<param name="loggingDataBridgeClass" value="com.us.platform.thing.configuration.impl.ThingLoggingDataBridge" />
<param name="useJmx" value="true" />
<param name="baseLogLevelName" value="thing.logging.baselevel.core" />
</filter>
</appender>
<appender class="org.apache.log4j.net.SyslogAppender" name="syslog">
<param value="LOCAL4" name="facility"/>
<param value="localhost" name="SyslogHost"/>
<layout class="com.us.platform.thing.log.SyslogPatternLayout">
<param value="{%t} %N{loggingFeature}|%N{loggingComponent} [%D] - %p %m%n" name="ConversionPattern"/>
</layout>
<filter class="com.us.platform.thing.log.filter.DynamicLevelFilter">
<param name="loggingDataBridgeClass" value="com.us.platform.thing.configuration.impl.ThingLoggingDataBridge" />
<param name="useJmx" value="true" />
<param name="baseLogLevelName" value="thing.logging.baselevel.core" />
</filter>
</appender>
<appender class="org.apache.log4j.net.SyslogAppender" name="catalina">
<param value="LOCAL1" name="facility"/>
<param value="localhost" name="SyslogHost"/>
<layout class="com.us.platform.thing.log.SyslogPatternLayout">
<param value="{%t} %-5p %c - %m%n" name="ConversionPattern"/>
</layout>
</appender>
<logger name="com.mchange.v2.c3p0">
<!-- Warn level is necessary or passwords are sent to logs. -->
<level value="warn"/>
</logger>
<logger name="com.mchange.v2">
<level value="info"/>
</logger>
<logger name="org.hibernate">
<level value="info"/>
</logger>
<logger name="org.springframework">
<level value="info"/>
</logger>
<logger name="net.sf.ehcache">
<level value="info"/>
</logger>
<root>
<level value="info"/>
<appender-ref ref="stdout"/>
<appender-ref ref="syslog"/>
<appender-ref ref="catalina"/>
</root>
</log4j:configuration>
这是tomcat7-maven-plugin的配置,我知道它很大,我为所需的配置量道歉:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7-maven-plugin-version}</version>
<configuration>
<path>/</path>
<serverXml>${project.build.directory}/thing.tomcat.hosted.core/tomcat-core/conf/server.xml</serverXml>
<tomcatWebXml>${project.build.directory}/thing.tomcat.hosted.core/tomcat-core/conf/web.xml</tomcatWebXml>
<systemProperties>
<JAVA_OPTS>-Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m</JAVA_OPTS>
<com.sun.management.jmxremote.port>8004</com.sun.management.jmxremote.port>
<com.sun.management.jmxremote>true</com.sun.management.jmxremote>
<com.sun.management.jmxremote.ssl>false</com.sun.management.jmxremote.ssl>
<com.sun.management.jmxremote.authenticate>false</com.sun.management.jmxremote.authenticate>
<org.apache.tomcat.util.digester.PROPERTY_SOURCE>com.us.platform.thing.tomcat.startup.TomcatPropertySource</org.apache.tomcat.util.digester.PROPERTY_SOURCE>
<project.version>${project.version}</project.version>
<project.basedir>${project.basedir}</project.basedir>
</systemProperties>
<skip>${skipTomcat}</skip>
<additionalClasspathDirs>
<additionalClasspathDir>${basedir}/src/main/resources</additionalClasspathDir>
</additionalClasspathDirs>
</configuration>
<dependencies>
...
</dependencies>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
<skip>${skipTomcat}</skip>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
<configuration>
<skip>${skipTomcat}</skip>
</configuration>
</execution>
</executions>
</plugin>
当我手动指定log4j.xml文件的位置时,日志记录正常工作。
$ mvn tomcat7:run -DskipTomcat=false -Dlog4j.configuration=file:src/main/resources/log4j.xml
有什么显而易见的东西吗?
答案 0 :(得分:3)
您可以将log4j.properties或XML添加到systemProperties部分:
喜欢这个
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
<systemProperties>
<log4j.configuration>file:src/main/resources/log4j.properties</log4j.configuration>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</plugin>
答案 1 :(得分:0)
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
<systemProperties>
<log4j.configurationFile>file:src/main/resources/log4j.xml</log4j.configurationFile>
</systemProperties>
</configuration>
</plugin>