gpt4 book ai didi

xml - tomcat7-maven-plugin log4j : no appender could be found for logger (org. apache.catalina.startup.Catalina)

转载 作者:行者123 更新时间:2023-11-28 22:37:15 28 4
gpt4 key购买 nike

我无法初始化 log4j catalina 日志附加器 - 你知道我缺少什么吗?我知道这是一个基本问题,但我坚持这一点。我为 catalina 记录器添加了 org.apache.log4j.net.SyslogAppender 定义,但没有成功。


log4j:WARN 找不到记录器的附加程序 (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

有什么明显的突出之处吗?

最佳答案

您可以将 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>

关于xml - tomcat7-maven-plugin log4j : no appender could be found for logger (org. apache.catalina.startup.Catalina),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31658993/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com