0

如果我在应用程序中遇到任何异常,它会显示在 Eclipse 控制台上。但该异常未显示在位于 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>
4

2 回答 2

0

将此文件保存在基本目录中,

src/com.yourproject.web... 然后:

src/log4j.xml

有用!!!

于 2013-12-12T16:47:47.100 回答
0

我认为您应该发布打印异常堆栈跟踪的代码。
检查您是否使用e.printStackTrace();而不是Logger.error("some message", e);

于 2012-09-27T06:10:10.813 回答