Customize Apache log format

Source: Internet
Author: User
Tags control characters apache log

Transferred from: volume analytics, etc., but ignored Apache access logs! Apache logs can record every request of the website for the Administrator's reference. Especially when a website is faulty, Apache log files can provide a lot of useful information. By analyzing log files, locate the website issue. However, the default log format of Apache may not satisfy everyone's appetite. Sometimes we need to customize the format and content of Apache logs, such as adding content we are interested in, delete content that we are not interested in, or change the log file record format. In the httpd. conf file of Apache, you can use the logformat and customlog commands to customize the log file format and content. The formatting parameters of logformat and customlog are a string that is recorded in the log file when each request occurs. It can contain text strings and control characters such as "/T" and "/N" written to logs as they are. Other special characters can be escaped by backslash. The request itself is recorded by placing "%" escape characters in the format string. The following table lists the meanings of Apache log format strings.
% Percent sign (Apache2.0.44 or later)
% Remote IP Address
% Local IP Address
% B Number of bytes transmitted except the HTTP Header
% B The number of bytes transmitted except the HTTP header is displayed in CLF format, that is, when no Bytes are transferred, '-' instead of 0 is displayed.
% {Foobar} c The cookiefoobar content that is sent to the server in the request.
% D The time used by the server to process this request, in microseconds.
% {Foobar} e Environment Variable foobar Value
% F File Name
% H Remote Host
% H Protocol used by the request
% {Foobar} I The content of the Request Header foobar: sent to the server.
% L Remote Login Name (from identd, if supported), will get a "-" Unless identitycheck is set to "on "-".
% M Request Method
% {Foobar} n The content of the annotation foobar from another module.
% {Foobar} o Response Header foobar: content.
% 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. The value range of format is PID and TID (2.0.46 and later versions) And hextid (apr1.2.0 or a later version is required)
% Q Query string (If yes, "? "Boot, otherwise an empty string is returned)
% R The first line of the request.
% S Status. For internal redirection requests, this status indicatesOriginalRequest status.-%> S indicates the status of the last request.
% T Time, in common log time format (Standard English format)
% {Format} t Time, expressed in the format specified by strftime (3. (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 returned status (% s) is 401, it may be false)
% U The requested URL path, which does not contain a query string.
% V Standard servername that provides services for this request.
% V The name of the server set according to the UseCanonicalName 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 % C, but this is in conflict with the previous SSL Syntax: % {var} C)
% 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.
 
Common format strings: Common log format (CLF)
"% H % L % u % t/" % R/"%> S % B"
General log format with VM
"% V % H % L % u % t/" % R/"%> S % B"
NCSA extension/combined log format
"% H % L % u % t/" % R/"%> S % B/" % {Referer} I/"% {User-Agent} I /""
Referer log format
"% {Referer} I-> % u"
Agent (browser) log format
"% {User-Agent} I"

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.