...
Code Block |
---|
language | xml |
---|
title | Rotating the log depending on a period |
---|
collapse | true |
---|
|
<?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.DailyRollingFileAppender">
<!-- not supported by DailyRollingFileAppender param name="MaxBackupIndex" value="7"/-->
<param name="Append" value="true" />
<param name="File" value="${LOGFILE}.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<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> |
The entry <param name="DatePattern" value="'.'yyyy-MM-dd"/>
specifies the rotation frequency:
Frequency | Configuration Sample |
---|
Rotate every minute | <param name="DatePattern" value="'.'yyyy-MM-dd-hhmm" /> |
Rotate every hour | <param name="DatePattern" value="'.'yyyy-MM-dd-hh" /> |
Rotate every day | <param name="DatePattern" value="'.'yyyy-MM-dd"/> |
Rotating the log depending on the size
Code Block |
---|
language | xml |
---|
title | Rotating the log depending on the size |
---|
collapse | true |
---|
|
<?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> |
...
This will create a new file .log.n
(n=1..5) when the size exceeds 2KB. You also can specify 20MB etc. The maximum value for n
is 13.
...
If you want to compress the rotated logs, please check the $SCHEDULER_HOME/lib/3rd-party
folder log/log4j
folder for availability of the file apache-log4j-extras-1.2.xx.jar
.
It should be provided with
Jira |
---|
server | SOS JIRA |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
key | SET-62 |
---|
|
Should this file not be available then download it from
https://logging.apache.org/log4j/extras/download.html...
Code Block |
---|
language | xml |
---|
title | Rotating and compressing the log depending on a period |
---|
collapse | true |
---|
|
<?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> |
...
The entry <param name="FileNamePattern" value="${LOGFILE}.%d{yyyyMMdd-hh}.log" />
specifies the rotation frequency:
Frequency | Configuration Sample |
---|
Rotate every minute | <param name="FileNamePattern" value="${LOGFILE}.%d{yyyyMMdd-hhmm}.log" /> |
Rotate every hour | <param name="FileNamePattern" value="${LOGFILE}.%d{yyyyMMdd-hh}.log" /> |
Rotate every day | <param name="FileNamePattern" value="${LOGFILE}.%d{yyyyMMdd}.log" /> |
Rotating and compressing the log depending on the size
Code Block |
---|
language | xml |
---|
title | Rotating and compressing the log depending on the size |
---|
collapse | true |
---|
|
<?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>
|
...
This will create a new file .n.log
(n=1..5) whenever the size exceeds 20KB. You also can specify 20MB etc. The max value for n
ist 13.
Show If |
---|
|
Deleting old log filesAs log4j does not provide deleting of old files (maxBackupIndex does not work for all appenders), you should implement a file deletion job on the master. For each agent, you have do define a seperate job. Code Block |
---|
language | xml |
---|
title | Deleting old files |
---|
| <job title="Remove temporary files" order="no" process_class="vmubuntu2" name="CleanupLogFiles">
<description >
<include file="jobs/JobSchedulerCleanupFiles.xml"/>
</description>
<params >
<param name="file_path" value="./logs"/>
<param name="file_spec" value="^.*\.log.gz$"/>
<param name="file_age" value="00:03"/>
</params>
<script language="java" java_class="sos.scheduler.job.JobSchedulerCleanupFiles"/>
<run_time >
<weekdays >
<day day="1 2 3 4 5 6 7">
<period single_start="23:00"/>
</day>
</weekdays>
</run_time>
</job> |
|