Apache Log optimization and apache Log

Source: Internet
Author: User
Tags apache log

Apache Log optimization and apache Log
When apache is running, information about all the requests it processes is recorded. at the same time, information about exceptions occurred during the processing is also recorded. the server can record request-related activity information in multiple log files in multiple formats, but only one error message can be recorded. activity records are written to log content only after the request is processed. for example, when a large file is uploaded, it is written into the log after the file is uploaded. the error message is written when an error occurs. of course, an error occurs in an instant. there will be no such long request processing. there is a common log display method: CLF (common log format ). the format is "% h % l % u % t \" % r \ "%> s % B". However, with the development, this format does not have enough content, another format is organized: "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "\" % {User-agent} I \" "It can remember the name and version of the requested browser version and other client software. apache comes with a standard Log Module: mod_log_config. in addition, Apache 2.0 has an additional module: mod_logio. it is the enhanced version of the former. and there are other third-party modules available in the module registration area of the http://modules.apache.org. for example, my Apache httpd. the conf file has the following configuration: ErrorLog "logs/error. log "LogLevel warn <IfModule log_config_module>LogFormat "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "\" % {User-Agent} I \ "" combinedLogFormat "% h % l % u % t \" % r \ "%> s % B" common<IfModule logio_module>LogFormat "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "\" % {User-Agent} I \ "% I % O" combinedio</IfModule>CustomLog "logs/access. log "common </IfModule> has two files under the logs directory under the My Apache installation directory: the error configured above. log and access. the configuration above the log defines the log output of Apache error information first. the log output level is defined. there are several levels:

 Level name Introduction
Emerg Emergency; Unavailable Server
Alert Action must be taken immediately
 Crit Critical Condition
 Error Error
 Warn Warning
 Notice Normal, but pay attention to the situation
 Info Common Information
 Debug Debug level information, including module running status
Once a level is set, it is recorded in the log file and the logs of the above level. However, whether set to a value, the notice level information will always be recorded.
Log Format String:
Format String Description
%% Percent sign (Apache2.0.44 or later)
%a Remote IP Address
%A Local IP Address
%B Number of bytes transmitted except the HTTP Header
%b The number of bytes transmitted except the HTTP header displayed in CLF format, that is, when no Bytes are transmitted'-'Instead of 0.
%{Foobar}C Cookie sent to the server in the requestFoobar. Values in cookies
%D The time used by the server to process this request, in microseconds.
%{FOOBAR}e Environment VariableFOOBARValue
%f File Name
%h Remote Host
%H Protocol used by the request
%{Foobar}i Request Header sent to the serverFoobar:.
%l Remote Login Name (from identd, if supported), unless IdentityCheck is set"On", Otherwise, a"-"is returned "-".
%m Request Method
%{Foobar}n Annotations from another moduleFoobar.
%{Foobar}o Response HeaderFoobar:.
%p The standard port on which the server serves the request.
%P The PID of the subprocess that provides services for this request.
%{format}P PID or TID (thread ID) serving the request ),formatThe value range is:pidAndtid(2.0.46 and later versions) Andhextid(APR1.2.0 or later is required)
%q Query string (if any"?"Boot; otherwise, an empty string is returned)
%r The first line of the request (request url and method)
%s Status. For internal redirection requests, this status indicatesOriginalRequest status ,---%>sThe status of the last request.
%t Time, in common log time format (Standard English format)
%{format}t Time,strftime(3)The time in the specified format. (By default, the local format is used)
%T The time taken to process the request, in seconds.
%u Remote User Name (based on the authentication information; if the return status (%s) Is 401, which may be false)
%U The requested URL path, which does not contain a query string.
%v Standard ServerName for the service provided by the request
%V The name of the server set according to the UserCanonicalName command.
%X Connection status when the request is complete:
X= The connection is interrupted before the response is completed.
+= The connection continues after the response is sent.
-= Close the connection after the response is sent.

(In Versions later than 1.3, this command is%cBut it is similar to the previous SSL Syntax:%{var}cConflict)

%I The number of bytes received, including the request header data, and cannot be zero. To use this command, you must enable the mod_logio module.
%O The number of bytes sent, including the data in the request header, and cannot be zero. To use this command, you must enable the mod_logio module.

Request logs are recorded by day or hour======================================================== Use CustomLog and rotatelogs (the bin directory of apache already contains: rotatelogs.exe. directories in linux may be different): CustomLog "| bin/rotatelogs logs/access_log. % Y-% m-% d 86400 "combined this configuration will output logs to another program, not files. that is, rotatelogs.exe. in this way, we can generate a new file without restarting Apache. this script will automatically open new files at a specified time and write logs. the first parameter of rotatelogs is the path and name of the log file: logs/access_log. % Y-% m-% d 86400 if it contains more than one % character, it will be processed as the strftime (3) format string; The above format indicates the year and month crystal. otherwise, a ten-digit Update time (in seconds) will be appended to the file name. for example, if the file name is foo, a log file such as foo.1234567890 will be generated. the above file will produce: access_log.2011-04-25 such a file. the second parameter is the interval between two updates (in seconds ). when the system time is a multiple of this parameter value, it will generate an update operation. for example, if this condition is set to 86400 seconds a day, a new log file will be generated every midnight every day.

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.