Apache Log Cutting

Source: Internet
Author: User
Tags apache log

System in the daily work will record a lot of file logs, if they are placed in a, we in the collation of the search, will be very cumbersome, increase the workload, so we have to use the log cutting, so that we classify the archive.

First, edit the virtual host configuration file

[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

We'll open the Customlog and errorlog and change the URL to our main domain,

Errorlog "Lam.com-error_log"

Customlog "Lam.com-access_log" common

(Add: We can view the log file in the "Log directory":/usr/local/apache2/logs directory. )

Then we edit the "Master profile"

[Email protected] ~]# vim/usr/local/apache2/conf/httpd.conf

Query/common, find

Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" Combined

We know that combined is better than common and can use custom formats like Combinedio,

(%h is ip,%u is the user,%t is the time,%r is the action ,%{referer}i is the Forum homepage)

So here we use combined, To edit a virtual host configuration file:

Customlog "Lam.com-access_log" common changed to combined, i.e.

Customlog "Lam.com-access_log"combined

Finally, we need to archive the logs on a daily basis, i.e. "cut", and delete the old logs.

Edit a virtual host configuration file

[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Errorlog information is too small, do not need to show too meticulous, generally do not change;

customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/lam.com-access_%y%m%d_log 86400" combined

: Wq

[Email protected] ~]# apachectl-t

[Email protected] ~]# Apachectl-restart

View the log directory

[Email protected] ~]# Ls/usr/local/apache2/logs

Error_log Lam.com-access_20150711_log

Apache Log Cutting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.