Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
titleRotating the log depending on the size
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" 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{yyyy-MM-dd HH:mm:ss,SSS Z} [%-5p] %c - %m%n" />
        </layout>
    </appender>
    <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
        <param name="Append" value="true" />
        <param name="File" value="${LOGFILE}.log" />
        <param name="MaxFileSize" value="2KB" />
        <param name="MaxBackupIndex" value="5" />
        
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%-5p] %c - %m%n"/>
        </layout>
    </appender>
    <root>
        <priority value="debug"/>
        <appender-ref ref="FILE"/>
    </root>
</log4j:configuration>

...

Rotating and compressing the log depending on a period

...

Code Block
languagexml
titleRotating and compressing the log depending on a period
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" 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{yyyy-MM-dd HH:mm:ss,SSS Z} [%-5p] %c - %m%n" />
        </layout>
    </appender>
      <appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
        <param name="Append" value="true" />
        <param name="File" value="${LOGFILE}.log" />
        
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="ActiveFileName" value="${LOGFILE}.log"/>
            <param name="FileNamePattern" value="${LOGFILE}.%d{yyyyMMdd-hh}.log.gz" />        
        </rollingPolicy>
        
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%-5p] %c - %m%n"/>
        </layout>
    </appender>
      <root>
        <priority value="debug"/>
        <appender-ref ref="FILE"/>
    </root>
</log4j:configuration>

...

Rotating and compressing the log depending on the size

...

Code Block
languagexml
titleRotating and compressing the log depending on the size
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" 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{yyyy-MM-dd HH:mm:ss,SSS Z} [%-5p] %c - %m%n" />
        </layout>
    </appender>
    <appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
        <param name="Append" value="true" />
        <param name="File" value="${LOGFILE}.log" />
        
        <rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
            <param name="ActiveFileName" value="${LOGFILE}.log"/>
            <param name="maxIndex" value="5"/>
            <param name="FileNamePattern" value="${LOGFILE}.%i.log.gz"/>        
        </rollingPolicy>
        <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
            <param name="maxFileSize" value="2048"/>        
        </triggeringPolicy>
        
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%-5p] %c - %m%n"/>
        </layout>
    </appender>
    <root>
        <priority value="debug"/>
        <appender-ref ref="FILE"/>
    </root>
</log4j:configuration>

...