tags:

views:

850

answers:

1

Hi,

Problem i have with log4j is that when i specify maxfilesize it works properly for the files generated in the src folder of project, but the log files generated in tomcat bin, are not splited into seperate files and then i have a large log file which is not desirable. The following is log4j.xml:

  <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
    <log4j:configuration>
        <appender name="fatalFile" class="org.apache.log4j.RollingFileAppender">
            <param name="MaxFileSize" value="100KB" />
            <param name="MaxBackupIndex" value="5" />
            <param name="File" value="logs/pnusn/fatal.log" />
            <param name="threshold" value="fatal" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%5p in Class:%C{2}, Thread:%t, at:%d{ABSOLUTE}:: '%m'%n" />
            </layout>
        </appender>
        <appender name="othersFile" class="org.apache.log4j.RollingFileAppender">
            <param name="MaxFileSize" value="100KB" />
            <param name="MaxBackupIndex" value="5" />
            <param name="File" value="logs/pnusn/others.log" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%5p in Class:%C{2}, Thread:%t, at:%d{ABSOLUTE}:: '%m'%n" />
            </layout>
            <filter class="org.apache.log4j.varia.LevelRangeFilter">
                <param name="LevelMin" value="debug" />
                <param name="LevelMax" value="error" />
            </filter>
        </appender>
        <appender name="traceFile" class="org.apache.log4j.RollingFileAppender">
            <param name="MaxFileSize" value="200KB" />
            <param name="MaxBackupIndex" value="20" />
            <param name="File" value="logs/pnusn/trace.log" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%5p in Class:%C{2}, Thread:%t, at:%d{ABSOLUTE}:: '%m'%n" />
            </layout>
            <filter class="org.apache.log4j.varia.LevelRangeFilter">
                <param name="LevelMin" value="trace" />
                <param name="LevelMax" value="trace" />
            </filter>
        </appender>
        <root>
            <priority value="trace"></priority>
            <appender-ref ref="fatalFile" />
            <appender-ref ref="othersFile" />
            <appender-ref ref="traceFile" />
        </root>
    </log4j:configuration>

Does anybody know how can i fix it?

Thanks for your consideration.

A: 

The log4j log files are appearing in your tomcat's bin directory because you haven't told it to do otherwise.

The tomcat docs here describe how to integrate log4j, including the use of the ${catalina.out} substitution to refer to the tomcat root directory. The instructions refer to the log4j properties file format, too, it's not clear if it'll work for log4j.xml

As for the file size problem, I'm not sure why that's happening. Try using the DailyRollingFileAppender instead, and see if that works.

skaffman