4.2.3 Dividing logs (rotatelogs program)
You can divide access logs and error logs by a specific time period (for example, every 24 hours) and output the logs to multiple files. The rotatelogs program can be specified in the following directives:
- CustomLog directive
- ErrorLog directive
- HWSRequestLog directive
- TransferLog directive
Specify the program in the following format.
- Organization of this subsection
- (1) Format
- (2) Parameters
- (3) How to use
- (4) Notes
(1) Format
rotatelogs prefix-for-split-log-file log-splitting-time-interval [-fnum number-of-files] [-diff time-difference-from-GMT] |
(2) Parameters
- Prefix-for-split-log-file
This parameter specifies the prefix of split log file with an absolute path.
Collect the log in the file called 'Prefix.nnnnnnnnnn' file.
- nnnnnnnnnn: Displays the log collection start time. The log collection time refers to a value displayed in the following format:
- (The value rounded off after the decimal point of (number of seconds taken to output the log, when the starting time is January 1, 1970 at 00:00:00 (GMT: Greenwich Mean Time)
log splitting time interval))
log splitting time interval
- log-splitting-time-interval ~ ((1-31536000))
This parameter specifies the time interval to collect one log file in seconds. The log is collected in a new file every time when the specified time elapses.
- -fnum number-of-files ~ ((1-256))
This parameter specifies the maximum number of split log files. If the number of split files exceeds the maximum number specified with this parameter, the files starting from the oldest file are deleted. If you do not specify this parameter, the log files are not deleted.
- -diff time-difference-from-GMT ((-1439-1439))
This parameter specifies the time offset (in minutes) from GMT for splitting the log files. If you do not specify the standard time, or if you specify 0, January 1, 1970 at 00:00:00 (GMT) is the standard time. When difference in local time with respect to GMT is n hours, and if m hours 0 minute 0 second of the local time is the standard time, specify (n - m)
60. If 0 hours 0 minute 0 second of JST is the standard time, specify 540 in (+ 9 - 0)
60.
(3) How to use
Use the rotatelogs after specifying " | Program name" format in the TransferLog, CustomLog, and the ErrorLog directives. The rotatelogs splits the log file periodically into separate files to collect the logs.
- (Example) Windows version
- This example explains how to split the access log after every 24 hours, and to collect the log in the file <Cosminexus-installation-directory>\httpsd\logs\access.nnnnnnnnnn on Windows. The following is the specification, where you set the splitting time as per the Japan Time, and split the log file at every 0 hrs of Japan time:
TransferLog "|\"\"<Cosminexus-installation-directory>/httpsd/sbin/rotatelogs.exe\" \"<Cosminexus-installation-directory>/httpsd/logs/access\" 86400 -diff 540\"" |
- Log file name: <Cosminexus-installation-directory>\httpsd\logs\access.nnnnnnnnnn
- Log splitting time interval: 86400 seconds (= 24 hours)
- (Example) UNIX version
- This example describes how to split the access log after every 24 hours, and to collect the log in /opt/hitachi/httpsd/logs/access.nnnnnnnnnn file on UNIX. The following is the specification, where you set the splitting time as per the Japan Time, and split the log file at every 0 hrs of Japan time:
TransferLog "|/opt/hitachi/httpsd/sbin/rotatelogs /opt/hitachi/httpsd/logs/access 86400 -diff 540" |
- Log file name: /opt/hitachi/httpsd/logs/access.nnnnnnnnnn
- Time interval to divide the log: 86400 seconds ( = 24 hours)
(4) Notes
(a) Notes for the UNIX version
- The rotatelogs2 program does not end the process even if a SIGTERM, SIGUSR1 or SIGHUP signal is received, but ends the process when the control process and server process end.
(b) Notes for the Windows version
- When you start the Web server as a service, the control process log is not collected.
- You cannot delete the log file until the process that has opened the file still exists. As a result, the number of files remaining might be more than the value specified for -fnum. For example, control process log files are deleted only when the control process ends.
- If an incorrect argument is present at startup, the Web server starts but the rotatelogs program does not start. The rotatelogs program outputs messages that contain the following attributes to the event log:
- Type: Error
- Source: CosminexusHTTPServer
- Class: none
- Event: 3299
- Description: rotatelogs.exe: (message)
For the meaning of output messages, see 23.9(6) rotatelogs program in the manual Cosminexus Application Server Messages.
When this message is displayed, follow the instructions in the message and specify valid arguments before restarting the server. Note that the same message might be output multiple times.
(c) Common notes for the UNIX and Windows versions
- For controlling the log file as per the -fnum parameter specification when you restart the Web server, if there is a change in the directory name or the log file prefix, the log file that is previously extracted is not deleted. In such cases, delete the log file based on the operation.
- When the specified time interval to split the log elapses since the Web server is started or restarted, and if the number of files matching to the prefix for split log files exceeds the value specified in the -fnum parameter, the files are deleted from the oldest files onwards.
- Specify the prefix-for-split-log-files with an absolute path.
- If an argument is not specified correctly in the rotatelogs program for TransferLog, CustomLog, ErrorLog, and HWSRequestLog directives, the rotatelogs program fails to start but the Web server starts properly. In this case, logs are not output. When you specify the rotatelogs program for TransferLog, CustomLog, ErrorLog, and HWSRequestLog directives, make sure that log files are created and the files are divided as you intended.