1. apache logs are recorded by date. in the apache configuration file, locate errorlogs/error_logcustomlogs/access_logcommonLinux system configuration method: Change it to ErrorLog & ldquo; |/usr/local/apache/bin/rotatelogs/hom "/>
1. apache logs are recorded by date
In the apache configuration file, find
ErrorLog logs/error_log
CustomLog logs/access_log common
Linux system configuration method:
Change it
ErrorLog "|/usr/local/apache/bin/rotatelogs/home/logs/www/% Y _ % m _ % d_error_log 86400 480 ″
CustomLog "|/usr/local/apache/bin/rotatelogs/home/logs/www/% Y _ % m _ % d_access_log 86400 480" common
Configuration method in Windows:
# ErrorLog "| bin/rotatelogs.exe logs/vicp_net_error-% y % m % d. log 86400 480 ″
# CustomLog "| bin/rotatelogs.exe logs/vicp_net_access-% y % m % d. log 86400 480" common
If you do not know how to set the 480 parameter for the first time, the log record time is 8 hours different from the server time. it turns out that rotatelogs has an offset parameter, which indicates the time difference (in minutes) relative to UTC and China is the eighth time zone, the difference is 480 minutes. 86400 indicates a day.
Appendix rotatelogs description
Rotatelogs logfile [rotationtime [offset] | [filesizeM]
Option
Logfile
The reference name is the log file name. If logfile contains '%', it is considered as a string in strftime (3) format; otherwise, it is automatically added with the. nnnnnnnnnn suffix in seconds. Both formats indicate the start time of the new log.
Rotationtime
Interval of log file rollback in seconds
Offset
The number of minutes relative to the UTC time difference. If it is omitted, it is assumed that it is 0 and UTC time is used. For example, to specify the local time of the area with the UTC time difference of-5 hours, this parameter should be-300.
FilesizeM
Specify the size of the file with the suffix M in MB when you roll back, instead of specifying the rollback time or time difference.
II. set apache Logging format
The format of the custom log file involves two commands, namely the LogFormat command and the CustomLog command. by default, the httpd. conf file provides several examples of these two commands.
The LogFormat command defines the format and specifies a name for the format. then we can directly reference this name. The CustomLog command sets the log file and specifies the format used by the log file (usually by the format name ).
The function of the LogFormat command is to define the log format and specify a name for it. For example, in the default httpd. conf file, we can find the following line of code:
LogFormat "% h % l % u % t" % r "%> s % B" common
Network Management Alliance www.bitsCN.com
This command creates a log format named "common". The log format is specified in the content enclosed by double quotation marks. Each variable in the format string represents a specific information, which is written to the log file in the order specified by the format string.
The Apache document has provided all the variables that can be used for format strings and their meanings:
%... A: remote IP address
%... A: local IP address
%... B: Number of sent bytes, excluding the HTTP header
%... B: Number of sent bytes in CLF format, excluding the HTTP header. For example, if no data is sent, write '-' instead of 0.
%... {FOOBAR} e: content of the environment variable FOOBAR
%... F: file name
%... H: remote host
%... H request protocol
%... {Foobar} I: Content of Foobar, the header row of the request sent to the server.
%... L: remote login name (from identd, if provided)
%... M request method
%... {Foobar} n: content of the annotation "Foobar" from another module
%... {Foobar} o: Content of Foobar, response header line
%... P: port used by the server to respond to the request
%... P: the ID of the subprocess that responds to the request.
%... Q query string (if a query string exists, it contains "?" Otherwise, it is an empty string .)
%... R: The first line of the request.
%... S: status. For internal redirection requests, this refers to the status of * original * requests. If %…> S, that is, later requests.
%... T: Time in the format of public log time (or standard English format)
%... {Format} t: Time in the specified format
%... T: The time it takes to respond to the request, in seconds
%... U: Remote User (from auth; if the returned status (% s) is 401, it may be forged)
%... U: URL path requested by the user
%... V: ServerName of the server responding to the request
%... V: the server name obtained based on UseCanonicalName
Among all the variables listed above, "…" Indicates an optional condition. If no condition is specified, the value of the variable is replaced. The default httpd is used before the analysis. the example of the LogFormat command in the conf file shows that it creates a log format named "common", including: remote host, remote login name, remote user, request time, the first line of the request code, the request status, and the number of bytes sent.
Sometimes we only want to record some specific and defined information in the log, then we need to use "…". If one or more HTTP status codes are put between "%" and the variable, only when the returned status code belongs to the specified status code, the content represented by the variable is recorded. For example, if you want to record all invalid links of a website, you can use:
LogFormat % 404 {Referer} I BrokenLinks
If we want to record requests whose status code is not equal to the specified value, we only need to add a "!" Symbol:
LogFormat %! 200U SomethingWrong
3. specially record a spider record
SetEnvIfNoCase User-Agent baiduspbaidu_robot
LogFormat "% h % t" % r "%> s % B" robot
Linux
CustomLog "|/usr/local/apache2.2.0/bin/rotatelogs/usr/local/apache2.2.0/logs/baidu_policy?m=d.txt 86400 480" robot env = baidu_robot
Windows
CustomLog "| bin/rotatelogs.exe logs/baidu_policy?m=d.txt 86400 480" robot env = baidu_robot
In this example, the log of "baidu_ .txt" is generated every day in the logs Directory. each record is similar to the following:
61.135.168.14 [22/Oct/2008: 22: 21: 26 + 0800] "GET/HTTP/1.1" 200 8427
4. remove images, js, css, and swf files from logs.
SetEnv IMAG 1
CustomLog "| bin/cronolog.exe logs/cpseadmin/access _ % Y % m % d. log" combined env =! IMAG