Found in Apache configuration file httpd.conf
Errorlog logs/error_log//error log
Customlog Logs/access_log common//access log
Why do you want to split the log
As the Web site access to more and more large, webserver generated log files will be more and more large, if not split the log, then can only be a large log (such as Apache log) the entire deletion, so also lost a lot of valuable information on the site, because these logs can be used for access analysis, Historical security monitoring, historical monitoring and so on, so the management of these massive logs on the meaning of the site is very large.
This article will summarize some useful log segmentation methods, hoping to be able to facilitate the Linux/unix administrator to effectively manage the log file, if the file too large, you can delete some historical files.
one, with the Apache system rotatelogs log truncation processing
1, repair file http.conf, set the following: With the following settings.
Errorlog "| /usr/local/apache/bin/rotatelogs /home/apache_log/www.xxx.com.cn/%y_%m_%d_error_ Log 86400 480 "
customlog" | /usr/local/apache/bin/rotatelogs /home/apache_log/www.xxx.com.cn/%y_%m_%d_access_log 86400 480 "common
2, restart the Apache service and verify it in the specified log directory.
3, parsing
rotatelogs [-l] logfile [rotationtime [ Offset]] | [Filesizem]
rotationtime //log files are scrolled in seconds
filesizem // Specify to scroll with filesizem file size;
example:
1. Rolling log files by time:
Error log: errorlog "|/data/apache/bin/rotatelogs log storage directory/%y%m%d_error.log 86400 480"
Access log: Customlog "|/data/apache/bin /rotatelogs Log storage directory/%y%m%d_access.log 86400 480 "Common
Where:
/data/ Apache: For the Apache installation directory, according to their actual situation determined;
86400: seconds, 24 hours, indicates that the generated log files are scrolled by day, that is, a log file is generated daily;
480: Minute, time offset.
Similarly, you can scroll the log files by the hour, every one hours, a few hours ... Generate a log file.
extension: Can write a script to delete log files, only a few days of the log, if the site traffic is large, a day will generate dozens of hundred m or even larger log files, both the hard disk and affect server performance. the shell script that clears the log file is then created, and the file name is Clean_log
#! /bin/bash
Logdir=/var/log/httpd
CD ${logdir}
Declare-i filesum= ' ls access_log.* | Wc-l '
Declare-i delnum= $filesum-3
if ["${delnum}"-ge 1];then
Rm-rf ' Ls-tr access_log.* | Head-${delnum} '
Fi
chmod 755 Clean_log
This preserves the last 3 days of log files.
Build automated tasks
* * * */usr/local/crontab/clean_log
OK, that's it, it's easy. So you don't have to worry about the growing log files!
2. Scroll through the log files by size:
Error log: errorlog "|/data/apache/bin/rotatelogs-l log storage directory/%y%m%d_error.log 5M"
Access log: Customlog "|/data/apache/bin/rotatelogs-l log storage directory/%y%m%d_access.log 5M" common
Scrolls the log file when it reaches 5M.
4. File name format
errorlog.%y-%m-%d-%h_%m_%s-----------------ERRORLOG.YYYY-MM-DD-HH_MM_SS
%A full name of the week (local)
%a 3-character weekday name (local)
%B the full name of the month name (local)
%b a 3-character month name (local)
%c Date and time (local)
%d 2-digit number of days in one months
%H 2-digit hours (24-hour system)
%I 2-digit hours (12-hour system)
%j 3-digit number of days in a year
%M 2-digit number of minutes
%m 2-digit number of months
%p AM/PM12 hours of the afternoon (local)
%s 2-digit number of seconds
%u 2-digit number of weeks in the year (Sunday is the first day of the week)
%W 2-digit number of weeks in the year (Monday is the first day of the week)
%w 1-digit days of the week (Sunday is the first day of the week)
%x Time (local)
%x Date (local)
%Y 4-digit year
%y 2-digit year
%Z Time Zone Name
Percent sign "%" itself
Apache Log and log segmentation