我是JasperReport和Log4j的新手,现在我必须将与jasper报告相关的所有日志消息记录到新的日志文件中。截至目前,它写入日志文件和控制台位我希望它只在单独的日志文件上记录。如何实现这个目标。
这是我的log4j.xml文件。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss}] [%c{1}] %-5p :%L - %m%n" />
</layout>
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="console" />
<appender-ref ref="file" />
</appender>
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="true" />
<param name="maxFileSize" value="10MB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="${catalina.home}/logs/ITS_Server.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss}] [%c{1}] %-5p:%L - %m%n" />
</layout>
</appender>
<category name="org.hibernate">
<priority value="DEBUG" />
</category>
<category name="java.sql">
<priority value="debug" />
</category>
<root>
<level value="DEBUG" />
<appender-ref ref="file" />
</root> -->
</log4j:configuration>
请有人可以帮助我。
答案 0 :(得分:1)
你必须定义一个新的appender:
<appender name="jasper" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="true" />
<param name="maxFileSize" value="10MB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="${catalina.home}/logs/jasperReports.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss}] [%c{1}] %-5p:%L - %m%n" />
</layout>
</appender>
以新的类别作为参考:
<category additivity="false" name="net.sf.jasperreports">
<priority value="debug" />
<appender-ref ref="jasper"/>
</category>