我想将特定于应用程序的记录器重定向到 tomcat / logs / catalina.out 的单独文件中。
以下是驻留在 tomcat / lib 文件夹中 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 name="RollingFiles" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="${catalina.home}/logs/application.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p-%d-{%C}-%t-%x-%m%n"/>
</layout>
</appender>
<logger name="com.company">
<level value="debug"/>
</logger>
<root>
<priority value ="debug" />
<appender-ref ref="RollingFiles" />
</root>
</log4j:configuration>
以下是 tomcat / conf 文件夹中 logging.properties 的内容
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.prefix = manager.
4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler
但我仍然在catalina.out和application.log中获取所有记录器输出,但我不想在catalina.out中使用特定于应用程序的日志(即logger name =“com.company”)。请帮助我。
Tomcat版本:7.0.35
Java:1.7.0_45
Log 4j:log4j-1.2.16.jar
答案 0 :(得分:0)
尝试将log4j.xml文件移动到app根目录下: webbapps / [您的应用] / WEB-INF / classes
通过这种方式,您不依赖于特定的tomcat安装来进行日志记录,您可以在任何tomcat实例上部署应用程序,而无需更改默认的tomcat配置。
答案 1 :(得分:0)
问题是,我在我的项目中引用了一个jar,它有 org.pentaho.di.core.logging.LogWriter 类。它默认情况下将控制台记录器添加到根记录器中。
修复,将其从LogWriter
中删除