为什么log4j没有在tomcat的日志中显示错误消息?

时间:2012-09-27 05:54:10

标签: tomcat7 log4

如果我在应用程序中遇到任何异常,它将显示在eclipse控制台上。但是,该异常未显示在tomcat logs文件夹中的日志文件中。我在这里缺少什么吗?

以下是我的完整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>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

将此文件保存在基目录

src / com.yourproject.web ... then:

的src /的log4j.xml

它有效!!!