Log analysis in general is beyond the scope of this document, and not really part of the job of the web server itself. For more information about this topic, and for applications which perform log analysis, check the Open Directory.
The CustomLog directive now subsumes the functionality of all the older directives. The format of the access log is highly configurable. The format is specified using a format string that looks much like a C-style printf 1 format string. Some examples are presented in the next sections.
This defines the nickname common and associates it with a particular log format string. The format string consists of percent directives, each of which tell the server to log a particular piece of information. Literal characters may also be placed in the format string and will be copied directly into the log output. The quote character " must be escaped by placing a backslash before it to prevent it from being interpreted as the end of the format string.
The CustomLog directive sets up a new log file using the defined nickname. The filename for the access log is relative to the ServerRoot unless it begins with a slash. This standard format can be produced by many different web servers and read by many log analysis programs.
The log file entries produced in CLF will look something like this:. Another commonly used format string is called the Combined Log Format. It can be used as follows. This format is exactly the same as the Common Log Format, with the addition of two more fields. The access log under this format will look like:.
Multiple access logs can be created simply by specifying multiple CustomLog directives in the configuration file. For example, the following directives will create three access logs.
The first contains the basic CLF information, while the second and third contain referer and browser information. This example also shows that it is not necessary to define a nickname with the LogFormat directive. Instead, the log format can be specified directly in the CustomLog directive. There are times when it is convenient to exclude certain entries from the access logs based on characteristics of the client request. This is easily accomplished with the help of environment variables.
First, an environment variable must be set to indicate that the request meets certain conditions. This is usually accomplished with SetEnvIf.
Some examples:. As another example, consider logging requests from english-speakers to one log file, and non-english speakers to a different log file. In a caching scenario one would want to know about the efficiency of the cache.
A very simple method to find this out would be:. In that case a cache hit will log - , while a cache miss will log 1. In other cases, a literal "-" will be logged instead. Likewise, in the second example, the Referer will be logged if the HTTP status code is not , , or We can see the default log level in the default configuration file:.
As you can see, by default, we have Apache configured to log messages with a priority of "warn" and above. We will learn where Apache logs its messages in the following section. Apache can be told where to place its logs using server-wide logging specifications. You can also configure logging individually for each separate virtual host. To find out where the server logs information by default, we can open the default configuration file. This directive names the file where Apache will keep its error messages.
This means that when combined with the directive in the "apache2. The "access. Instead, the package maintainer decided to place the directive specifying its use within a virtual host definition.
The ErrorLog definition matches the one in the default configuration file. It is not necessary to have that line in both places, but it does not hurt to be specific incase you change the location in one place or another. In the previous section, the line describing the "access. It uses "CustomLog" to specify the access. The log format in this example is "combined".
This is not an internal Apache specification. Instead, this is a label for a custom format that is defined in the default configuration file. If we open the default config file again, we can see the line that defines the "combined" log format:. The "LogFormat" command defines a custom format for logs that can be called using the "CustomLog" directive as we saw in the virtual host definition.
This log format specifies a format known as a "combined" format. Learn more about available format string variables by going here. As you can see, there are several other common formats that have been created for use within your virtual host definitions. Home About Articles Presentations Subscribe. A blog without a catchy title by Peter Lorenzen. Follow theheatDK. Yes sorry did not notice there were two spaces in the path. Hi Peter, First of all thanks, I too was searching for this for ages.
Hi, I have implemented log rotation in Windows server R2 as shown below, but it is not working. Thanks in advance. Hi Hari, It looks like you are using the wrong quotes character. Thanks Hari. Hi Peter Apologies for late reply. Hi Peter, Do you know why i have a cmd. Hi Hari, The only idea I have is to input the full path to the rotatelogs. Hi Peter, I have tried even with full path to the rotatelogs. Could this work?
To overwrite weekly and limit the growth? Need assistance please. Hi Peter, Thanks for posting wonderful info. But when I put below entry alone. The filename of the newly opened file is passed as the first argument to the program. If executing after a rotation, the old log file is passed as the second argument. The spawned program uses the same stdin, stdout, and stderr as rotatelogs itself, and also inherits the environment. This allows strftime 3 formatting to be used in the path and not just the filename.
This is useful when a log is processed in real time by a command like tail, and there is no need for archived data. The output contains the result of the configuration parsing, and all file open and close actions.
Useful when logs need to be further processed in real time by a further tool in the chain. With -n 3, the series of log files opened would be "logfile", "logfile. Available in 2.
0コメント