如果我在應用程序中遇到任何異常,它將顯示在eclipse控制檯上。但該例外情況未顯示在位於tomcat日誌文件夾中的日誌文件中。有什麼我在這裏失蹤?爲什麼log4j沒有在tomcat的日誌中顯示錯誤消息?
以下是我的完整log4j文件。
<?xml version="1.0" encoding="UTF-8"?>
<!-- Document : log4j.xml Created on : Feb 23, 2012, 9:30 AM Author : meshash
Description: Purpose of the document follows. -->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- ====================================================================== -->
<!-- A P P E N D E R S -->
<!-- ====================================================================== -->
<!-- console -->
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="Threshold" value="INFO" />
<param name="ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %M - %m - (%F, line %L)%n" />
</layout>
</appender>
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<!-- <param name="Threshold" value="INFO" /> -->
<param name="File"
value="C:/DEV_HOME/server/apache-tomcat-7.0.29/logs/headcount.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m (%F, line %L)%n" />
</layout>
</appender>
<!-- ====================================================================== -->
<!-- L O G G E R S -->
<!-- ====================================================================== -->
<category name="org.springframework.jdbc.core.JdbcTemplate">
<priority value="debug" />
</category>
<root>
<level value="INFO" />
<appender-ref ref="consoleAppender" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
e.printStackTrace();會不會被記錄?那麼像NullPointerException這樣的運行時異常呢?即使NullPointerException不記錄到日誌文件。 – ashishjmeshram
e.printStackTrace();將登錄到System.err而不是log4j,除非您使用類似sysout-over-slf4j的方式重定向System.err – turtledove