Sometimes we need a custom Apache default log format and content, such as increase or decrease the logged information, change the default log file format, etc.
This article describes the available log records all the information, and how to set up Apache to record this information. First, define the log format (3 April) a long time ago, the log file is only one format, this is the format of the "public", many people have become accustomed to using this format. The resulting custom log formats, and looks more custom log format is very popular, even if the common log format itself is reapplied custom log format defined. This article describes is how freedom to customize the format of the log file, how to keep log files record the information you want. Customize the format of the log file involves two directives, namely the LogFormat directive and CustomLog directives, default httpd.conf files on these two directives by a few examples. LogFormat directive defines the format and specify a name for the format, then we can directly reference the name. CustomLog directive sets the log file and specifying the logs files format (usually by format name). LogFormat directive 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\"% s "% > r\% b" common the directive creates a "common" log format, the log format in quotation marks surround the content specified. Format string for each variable represents a specific information, the information provided in accordance with the format string in the order in written to the log file. Apache document already gives all can be used to format string variables and their meaning, the following is:% ...a: remote IP address% ... A: the local IP address% ... B: the number of bytes sent, does not contain HTTP header% ... b:CLF format of the number of bytes sent, does not contain the HTTP header. For example when not sending data, write the '-' instead of 0. %... {FOOBAR} e: environment variable FOOBAR content% ...f: file name% ...h: remote host% ... H the requested protocol% ... {Foobar} i:Foobar content, sent to the server for the requested header rows. % ...L: remote login name (from identd, if supplied)% ...m requested method% ... {Foobar} n: from another module of the note "Foobar" content% ... {Foobar} o:Foobar, response-header row% ...p: server to use when responding to requests on port% ... P: responding to the request ID of the child process. % ...Q query string (if there is a query string that contains "?" Later; otherwise, it is an empty string. )% ...R: request first row% ...s: State. For an internal redirect requests, this is the * original * the status of the request. If you use the% ... > s, refers to a subsequent request. % ...T: public log time format (standard English format or as)% ... {Format} t: to specify the format for the format of the time% ... T: in response to the request and the amount of time, in seconds% ...u: remote user (from auth; if return status (% s) is 401 may be forged)% ... U: user the requested URL path% ...v: responding to the request, server ServerName% ... According to the UseCanonicalName setting V: the server name in all of the variables listed above, the "..." indicates an optional conditions. If you do not specify the conditions, the variable's value will be replaced with "-". Analysis of previous from the default httpd.conf files LogFormat directives for example, you can see that it creates a "common" log formats, including: remote host name, remote login, remote user, request time, the first line of the code of the request, the requested State, and the number of bytes sent. Sometimes we just want to log some specific, defined information, then use the "...". If a "%" and variable has placed between one or more of the HTTP status code, only when the request returns the status code is one of the specified status code, the variable represents the content will be recorded. For example, if we want to record the site all the invalid links, then you can use: LogFormat% 404 {Referer} iBrokenLinks on the other hand, if we want to record the status code is not equal to the specified value of the request, simply adding a "!" Symbol: 200USomethingWrong LogFormat%!
No comments:
Post a Comment