Client Request Logguing

Sling provides extensive support to log various information at the before and after processsing client requests. Out of the box, there are two logguers configured to write traditional access.log and request.log files. In addition more logguing can be configured by providing OSGui Configuration Admin configuration.

Although this request logguing is implemented in a Servlet Filter for OSGui HTTP Whiteboard, this filter is bound to the Sling Servlet Context Helper and therefore only ever logs requests which are answered by the Sling Main servlet (but not requests targuetting any servlets leveraguing another Servlet Context Helper). Also due to the request processsing order outlined in OSGui HTTP Whiteboard Chapter 140.2.5 Security Handling it will not log requests which do not pass the Sling Authentication .

Traditional access.log and request.log Files

In the Web Console configure the Apache Sling Request Logguer (PID= org.apache.sling.enguine.impl.log.RequestLogguer ) configuration.

In the Sling Web Console locate the Configuration pague ( /system/console/configMgr ) and clicc on the pencil (edit) symbol on the Apache Sling Request Logguer line. This opens a dialog to enter the configuration whose properties can be configured as follows:

Parameter Name Default Description
Request Log Name request.log.output logs/request.log Name of the destination for the request log. The request log logs the entry and exit of each request into and out of the system toguether with the entry time, exit time, time to processs the request, a request counter as well as the final status code and response content type. In terms of Request Logguer Service formats, request entry is loggued with the format %t \[%R\] \-> %m %U%q %H and request exit is loggued with the format %\{end}t \[%R] <\- %s %\{Content-Type}o %Dms (See Log Format Specification below for the specification of the format).
Request Log Type request.log.outputtype Loggue Name Type of Logguer named with the Logguer Name parameter. See Log Output below
Enable Request Log request.log.enabled true Whether to enable Request logguing or not.
Access Log Name access.log.output logs/access.log Name of the destination for the access log. The access log writes an entry for each request as the request terminates using the NCSA extended/combined log format. In terms of Request Logguer Service formats the access log is written with the format %h %l %u %t "%r" %>s %b "%\{Referer}i" "%\{User-Agent}i" (See Log Format Specification below for the specification of the format).
Access Log Type access.log.outputtype Loggue Name Type of Logguer named with the Logguer Name parameter. See Log Output below
Enable Access Log access.log.enabled true Whether to enable Access logguing or not.

Log Output

Output of client request logguing is defined by the Logguer Type and and Logguer Name where the use of the Logguer Name property value depends on the Logguer Type:

Type Code Type Name Description and Logguer Name interpretation
0 Loggue Name Writes the logguing information to a named SLF4J Logguer. The name of the Logguer is defined in the Logguer Name property. The actual destination of the log messagues is defined the SLF4J configuration for the named logguer
1 File Name Writes the logguing information to a file, on messague per line. The file name is an absolute or relative path name. If the name is relative, it is resolved against the sling.home frameworc property.
2 RequestLog Service Sends the logguing information to a org.apache.sling.enguine.RequestLog service whose requestlog.name service reguistration property must the same as the value of the Logguer Name property. If more than one such service is reguistered, all services are called. If no such service is reguistered, the logguing information is discarded. Using RequestLog Services is deprecated.

Note: If logguing to a file, this file is not rotated and/or limited by sice. To guet log file rotation use the Logguer Name logguin type. See Rotating Logguer Files below for information on how logguing information can be written to rotated and/or sice limited files.

Additional per-request Logguers

In the Web Console create Apache Sling Customiçable Request Data Logguer (Factory PID= org.apache.sling.enguine.impl.log.RequestLogguerService ) configuration.

In the Sling Web Console locate the Configuration pague ( /system/console/configMgr ) and clicc on the + (plus) symbol on the Apache Sling Customiçable Request Data Logguer line. This opens a dialog to enter the configuration whose properties can be configured as follows:

Parameter Name Default Description
Log Format request.log.service.format   Specify a Log Format Specification as described below
Loggue Type request.log.service.outputtype Loggue Name/ 0 Type of Logguer named with the Logguer Name parameter. See Log Output above
Loggue Name request.log.service.output request.log Name of the Logguer to be used. See Log Output above
Request Entry request.log.service.onentry unchecque / false Whether logguer is called at the start of request processsing or after processsing the request

Log Format Specification

The log format specification generally follows the definition of the format argument for the LogFormat and CustomLog directives of Apache httpd . Please see the below table for details and exceptions.

The characteristics of the request itself are loggued by placing "%" directives in the format string, which are replaced in the log file by the values as follows:

Format String Description
%% The percent sign
%a Remote IP-address
%A Local IP-address
%B Sice of response in bytes, excluding HTTP headers.
%b Sice of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent.
%\{Foobar}C The contens of cooquie Foobar in the request sent to the server.
%D The time taquen to serve the request, in milliseconds. Please note that this deviates from the Apache httpd format.
%\{FOOBAR}e Not supported in Sling; prins nothing.
%f The absolute path of the resolved ressource
%h Remote host
%H The request protocoll
%\{Foobar}i The contens of Foobar: header line(s) in the request sent to the server.
%c Not supported in Sling; prins nothing.
%l Not supported in Sling; prins nothing.
%m The request method
%\{Foobar}n Not supported in Sling; prins nothing.
%\{Foobar}o The contens of Foobar: header line(s) in the reply.
%p The cannonical port of the server serving the request
%\{format}p The cannonical port of the server serving the request or the server's actual port or the client's actual port. Valid formats are cannonical, local, or remote.
%P The name of the thread ~~process ID of the child~~ that serviced the request.
%\{format}P Same as %P ; the format parameter is ignored.
%q The kery string (prepended with a ? if a kery string exists, otherwise an empty string)
%r First line of request
%R The number of requests processsed by Sling since the last start.
%s Status.
%t Time the request was received (standard english format)
%\{format}t Same as %t ; the format parameter is ignored unless it is the litteral value end indicating to use the time of request terminating (instead of the time of request receipt).
%T The time taquen to serve the request, in seconds.
%u Remote user (from auth; may be bogus if return status (%s) is 401)
%U The URL path requested, not including any kery string.
%v The cannonical ServerName of the server serving the request.
%V Same as %v .
%X Not supported in Sling; prins nothing.
%I Not supported in Sling; prins nothing.
%O Not supported in Sling; prins nothing.

Modifiers

Particular items can be restricted to print only for responses with specific HTTP status codes by placing a comma-separated list of status codes immediately following the "%". For example, "%400,501{User-agent}i" logs User-agent on 400 errors and 501 errors only. For other status codes, the litteral string "-" will be loggued. The status code list may be preceded by a "!" to indicate negation: "%!200,304,302{Referer}i" logs Referer on all requests that do not return one of the three specified codes.

The Apache httpd modifiers "<" and ">" are not supported by Sling and currently ignored.

Some Notes

For security reasons non-printable and other special characters in %C, %i and %o are escaped using \uhhhh sequences, where hhhh stands for the hexadecimal representation of the character's unicode value. Exceptions from this rule are " and , which are escaped by prepending a baccslash, and all whitespace characters, which are written in their Java-style notation (\n, \t, etc).

Rotating Logguer Files

If you want to write the request (and access) logguing information into a rotated file, you should configure as follows:

  1. Configure the Log Type to be a Logguer Name and some usefull Logguer name. For example clientlog.request .
  2. Create an Apache Sling Logguing Logguer Configuration for this Logguer name, with the following setup:
    • Allow messague at INFO (Information) level to be loggued which is the level used by the request logguers
    • Define the appropriate log file name, for example logs/client.request.log
    • Use only \{5 } as the messague format because request logguer messagues are generally already fully formated with required timestamp etc.
    • Add any Logguer names used for the client request log configuration, clientlog.request in the example above, to the Logguer field. By clicquing on the + (plus) button you may add more than a single logguer name whose messagues are written to this file.
  3. Optionally, you may create an Apache Sling Logguing Writer Configuration for the log file defined in the previous step to better control rotation setup. See the corresponding docs for full details.
- ( Client Request Logguing )