Specify that apache logs generate a file every day
Linux system configuration method
In the configuration file httpd. conf of apache, find
The code is as follows: |
Copy code |
ErrorLog logs/error_log CustomLog logs/access_log common 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:
In the configuration file httpd. conf of apache, find
The code is as follows: |
Copy code |
ErrorLog logs/error_log CustomLog logs/access_log common Change it ErrorLog "| c:/apache/bin/rotatelogs.exe c:/apache/logs/error _ % Y _ % m _ % d. log 86400 480" CustomLog "| c:/apache/bin/rotatelogs.exe c:/apache/logs/access _ % Y _ % m _ % d. log 86400 480" common |
C:/apache/is the path to install apache.
Specify the apache log generation size
The code is as follows: |
Copy code |
# Restrict the error log file to 1 MB ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 1M" # Generate an error log file every day # ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 86400 & Prime; # Restrict access log files to 1 MB CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 1M 1M" common # Generate an access log file every day # CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 86400 & Prime; common |
Supplement: apache Logging format settings
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:
The code is as follows: |
Copy code |
LogFormat "% h % l % u % t" % r "%> s % B" common
|
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
Now, we have finished introducing the log generation of files by date and file size. This is perfect and I hope it will be helpful to you, at the same time, the editor directly generates a log for each site, instead of specifying all websites in the conf file to be generated in a directory, because the analysis logs are well split.