Log optimization generally two aspects, log cutting and do not record the specified type of log, the following respectively explain the experiment these two categories
Apache Log Cutting
Here the log refers to the access log, each access will produce several logs, if not to manage, long time, log files will become larger and more difficult to view. So we archive the logs according to our needs, such as a new log every day. Rotatelogs can be achieved with a single tool from Apache.
Let's configure it to include in the corresponding virtual host configuration file
# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf
Errorlog "/usr/local/apache2/logs/test-error_log"
Customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/test-
Access_%y%m%d.log 86400 "combined
Note: Above is two lines, must not enter. Errorlog is the error log, and Customlog is the access log. The front vertical line is the pipe character, which refers to handing the customlog to the Rtatelogs tool. The function of-L is to calibrate the time zone to UTC, which is Beijing times. The back 86400, the unit is the second, refers to the day. Then the log will be cut once every day. The last combined is the log format, in which the httpd.conf has the definition of the log format.
# grep logformat/usr/local/apache2/conf/httpd.conf
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined
Logformat "%h%l%u%t \"%r\ "%>s%b" common
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "%I%O" Combinedio
Apache does not record the specified file type log
When a site has a large number of visits, there are many access logs, but in fact there are some access logs do not need to record, such as the site of some pictures, as well as JS, CSS and other static objects.
You can implement the above ideas by doing the configuration below
# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf
Errorlog "/usr/local/apache/logs/test-error_%y%m%d.log 86400"
Setenvif Request_uri ". *\.gif$" Image-request
Setenvif Request_uri ". *\.jpg$" Image-request
Setenvif Request_uri ". *\.png$" Image-request
Setenvif Request_uri ". *\.bmp$" Image-request
Setenvif Request_uri ". *\.swf$" Image-request
Setenvif Request_uri ". *\.js$" Image-request
Setenvif Request_uri ". *\.css$" Image-request
Customlog "|/usr/local/apache/bin/rotatelogs-l/usr/local/apache/logs/test-access_%y%m%d.log 86400" combined env=! Image-request
This article is from the "Liew" blog, make sure to keep this source http://walterliew.blog.51cto.com/11286797/1883747
Apache Log Optimization