2.0-apache Log Cutting

Source: Internet
Author: User
Tags apache log

Apache will generate access logs and error logs by default under/usr/local/apache2/logs after the service is available Access_log and error_log

In particular, the access log, in the case of multiple user access, will produce a lot of records. Over time, it may turn into a few g or more than 10 g.

In order to alleviate this situation, cutting logs by day, deleting previously useless logs, is a good workaround.


First of all, the system generates the Access log format by default:

Vim/usr/local/apache2/conf/httpd.conf

<ifmodule log_config_module>

#

# The following directives define some format nicknames for use with

# a Customlog directive (see below).

#

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

Logformat "%h%l%u%t \"%r\ "%>s%b" common


<ifmodule logio_module>

# need to enable MOD_LOGIO.C to use%I and%O

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

</IfModule>


There are three types of combined common and combinedio formats

The more commonly used are combined types

%h indicates that the source IP%u indicates that the user name%t represents the time%r represents the action, such as: GET detailed instructions, please see the official manual


Configuration steps:

1.vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Turn on the default logging feature

Errorlog "Logs/dummy-host.example.com-error_log"

Customlog "Logs/dummy-host.example.com-access_log" common


2. Modify the Access log type to combined

Customlog "Logs/dummy-host.example.com-access_log" combined


3. Add Cut command, post-cut log absolute path and custom timestamp log name Finally, add the cut condition, that is, 24 hours to cut once.

Customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/%y%m%d-access_log 86400" combined


Note: It is automatically cut on-the-go, separated by days, and it will automatically generate a new log file in the next second of 2015-01-03 23:59:59.


2.0-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.