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