Http://httpd.apache.org/docs/2.2/logs.html
Log Rotation
Log rotation
On even a moderately busy server, the quantity of information stored in the log files are very large. The access log file typically grows 1 MB or more per requests.
Even on a moderately busy server, the amount of information stored in the log file is very large. Access logs typically grow by 1M or more per 10,000 requests.
It'll consequently be necessary to periodically rotate the log files by moving or deleting the existing logs.
Therefore it is necessary to move or delete an existing log to cycle the log file.
This cannot was done while the server is running, because Apache would continue writing to the old log file as long as it ho LDS the file open.
When the server is running, it cannot be replaced because as long as Apache keeps the file open, it will continue to write old files.
Instead, the server must is restarted after the log files is moved or deleted so, it'll open new log files.
Therefore, the server must be restarted after the log file is moved or deleted so that the server can open a new log file.
By using a graceful restart, the server can be instructed to open new log files without losing any existing or pending con Nections from clients.
With an elegant restart, the server can be instructed to open a new log file without losing any connections that existed or were attempting to access from the client.
However, in order to accomplish this, the server must continue to write to the old log files and it finishes serving old Requests.
However, in order to achieve this goal, the server must continue to complete the old file while servicing the old request.
It is therefore necessary-to-wait for some time after the restart before doing any processing on the log files.
It is necessary to wait some time before doing any processing of the log files after the reboot.
A Typical scenario that simply rotates the logs and compresses the old logs to save space is:
A typical scenario that simply turns the log and compresses the old log to save space is:
MV Access_log Access_log.old
MV Error_log Error_log.old
Apachectl Graceful
Sleep 600
Gzip Access_log.old Error_log.old
Another-perform log rotation is using piped logs as discussed on the next section.
Another way to complete a log rotation is to discuss the pipeline log in the next section.
Piped Logs
Pipeline Log
Apache httpd is capable of writing error and access log files through a pipe to another process, rather than directly to a File.
Apache HTTPD has the ability to write errors and access logs to another process, rather than directly to a file, through one pipeline.
This capability dramatically increases the flexibility of logging, without adding code to the main server.
This capability significantly increases the flexibility of the recording without adding code to the primary server.
In order to write logs to a pipe, simply replace the filename with the pipe character ' | ', followed by the name of the EXE Cutable which should accept log entries on it standard input.
To write a log to a pipeline, simply use the pipe character | To replace the filename, followed by the executable name, which should accept the log entry on its standard input.
Apache would start the Piped-log process when the server starts, and would restart it if it crashes while the server is Runn Ing. (This, feature is, we can refer to this technique as "reliable piped logging".)
When the server starts, Apache initiates a pipeline log process, and the server runs at the same time if the pipeline can be restarted. (The last feature is why we can call this technology "reliable pipe Log")
Piped log processes is spawned by the parent Apache httpd process, and inherit the userid of this process. This means, piped log programs usually run as root.
The pipeline log process is derived from the httpd parent process and inherits the UID of the parent process. This means that the pipeline log program is typically run as root.
It is therefore very important to keep the programs simple and secure.
Therefore, it is very important to keep the program simple and safe.
One important use of piped logs are to allow log rotation without have to restart the server.
One important use of the pipeline log is to allow rotation without restarting the server.
The Apache HTTP Server includes a simple program called Rotatelogs for this purpose. For example, to rotate the logs every-hours, you can use:
The server contains a simple program called Rotatelogs to achieve this goal. For example, every 24 hours, you can use the rotation log:
customlog "|/usr/local/apache/bin/rotatelogs/var/log/access_log" CommonThis may not work properly, so use the following, add one of the following instructions, and then access the page, the log will be replaced in a minute.
Notice that quotes is used to enclose the entire command that would be called for the pipe. Although these examples is for the access log, the same technique can is used for the error log.
Note Double quotation marks are used to close the entire command that is called by the pipeline. Although this example is used to access logs, the same technique can be used for error_log.
As with conditional logging, piped logs is a very powerful tool, but they should isn't be used where a simpler solution lik E off-line post-processing is available.
By default, the piped log process is spawned using a shell. (usually with/bin/sh-c). Depending on the shell specifics invocation via shell might leads to a additional shell process for the lifetime of the LO Gging pipe program and signal handling problems during restart.
Use "| |" instead of "|" to spawn without invoking a shell:
# Invoke "Rotatelogs" without using a shell
Customlog "| | /usr/local/apache/bin/rotatelogs/var/log/access_log "Common
httpd-2.2