2.6.1 rotatelogs
rotatelogs splits logs by time and outputs them into multiple files.
Description
rotatelogs splits the access log or the error log by time (for example, in unit of 24 hours) and output the log into multiple files. You can specify the rotatelogs program in the following directives:
-
CustomLog directive
-
ErrorLog directive
-
HWSRequestLog directive
-
TransferLog directive
Syntax
rotatelogs prefix_of_log_files_to_be_generated_after_the_split time_interval_for_splitting_log [-fnum number_of_files] [-diff time_difference_from_GMT]
- prefix_of_log_files_to_be_generated_after_the_split
-
Specify the prefix, as an absolute path, of the log files to be generated after the split.
Logs will be collected into files whose names are in the format prefix.nnnnnnnnnn.
nnnnnnnnnn indicates the starting time when the log was obtained. The following formula is used to calculate the time when the log was obtained:
- time_interval_for_splitting_log
-
Specify the time interval (in seconds) for obtaining a log file. The log is collecting into a new file when the specified time elapses.
- Specifiable values
-
1 to 31536000
- -fnum number_of_files
-
Specify the maximum number of log files that can exist after the split. If the number of log files generated after the split exceeds this number, files are deleted in order from the oldest file. If this option is omitted, no files are deleted.
- Specifiable values
-
1 to 256
- -diff time_difference_from_GMT
-
Specify the time difference (in minutes) from GMT, which is used as the basic time for splitting the log file. If nothing or 0 (zero) is specified, the basic time is January 1, 1970, 00:00:00 (GMT). If the time difference between GMT and the local time is n hours and you want to set the m:00:00 (local time) as the basic time, specify the value obtained from the formula (n-m)*60. If you want to set 00:00:00 JST as the basic time, specify 540, which is calculated by the formula (+9-0)*60.
- Specifiable values
-
-1439 to 1439
Storage location
installation_directory_for_Application_Server/httpsd/sbin
Example
Specify the directive by using the "|program_name" format. The log file will be split and collected into separate files at regular intervals.
At 24-hour intervals, the access log is split and log entries are collected into the file installation_directory_for_Application_Server/httpsd/logs/access.nnnnnnnnnn. In the following example, the log file is split every day at midnight (00:00:00), Japan time:
TransferLog "|installation_directory_for_Application_Server/httpsd/sbin/rotatelogs installation_directory_for_Application_Server/httpsd/logs/access 86400 -diff 540"
-
Log file name: installation_directory_for_Application_Server/httpsd/logs/access.nnnnnnnnnn
-
Time interval for splitting the log: 86400 seconds (24 hours)
Notes
-
The rotatelogs program does not terminate processes when the SIGTERM, SIGUSR1 and SIGHUP signals are received. Processes will terminate when the control process and the server process terminate.
-
Regarding the control of log files by specifying the -fnum option is specified, if you change the directory name or the log file prefix when restarting the web server, the log files that were previously obtained will not be deleted. In this case, delete the files as needed.
-
After the startup or restart of the web server, when the specified interval for splitting the log elapses, if the number of files that have the prefix of log files generated after the split exceeds the value specified in the -fnum option, the log files are deleted in order from the oldest file.
-
Be sure to specify the prefix of the log files to be generated after the split, as an absolute path.
If an argument of the rotatelogs program is incorrect, the rotatelogs program does not start but the web server starts. In this case, logs are not output. If you specify the rotatelogs program, make sure log files are created and split as intended.