Class AccessLogHandler
- java.lang.Object
-
- io.undertow.server.handlers.accesslog.AccessLogHandler
-
- All Implemented Interfaces:
HttpHandler
public class AccessLogHandler extends Object implements HttpHandler
Access log handler. This handler will generate access log messages based on the provided format string, and pass these messages into the providedAccessLogReceiver
.This handler can log any attribute that is provides via the
ExchangeAttribute
mechanism. A general guide to the most common attribute is provided before, however this mechanism is extensible.This factory produces token handlers for the following patterns
- %a - Remote IP address
- %A - Local IP address
- %b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent
- %B - Bytes sent, excluding HTTP headers
- %h - Remote host name
- %H - Request protocol
- %l - Remote logical username from identd (always returns '-')
- %m - Request method
- %o - Obfuscated remote IP address (IPv4: last byte removed, IPv6: cut off after second colon, ie. '1.2.3.' or 'fe08:44:')
- %p - Local port
- %q - Query string (excluding the '?' character)
- %r - First line of the request
- %s - HTTP status code of the response
- %t - Date and time, in Common Log Format format
- %u - Remote user that was authenticated
- %U - Requested URL path
- %v - Local server name
- %D - Time taken to process the request, in millis
- %T - Time taken to process the request, in seconds
- %I - current Request thread name (can compare later with stacktraces)
In addition, the caller can specify one of the following aliases for commonly utilized patterns:
- common -
%h %l %u %t "%r" %s %b
- combined -
%h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}"
- commonobf -
%o %l %u %t "%r" %s %b
- combinedobf -
%o %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}"
There is also support to write information from the cookie, incoming header, or the session
It is modeled after the apache syntax:%{i,xxx}
for incoming headers%{o,xxx}
for outgoing response headers%{c,xxx}
for a specific cookie%{r,xxx}
xxx is an attribute in the ServletRequest%{s,xxx}
xxx is an attribute in the HttpSession
- Author:
- Stuart Douglas
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AccessLogHandler.Builder
-
Constructor Summary
Constructors Constructor Description AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ExchangeAttribute attribute)
AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ExchangeAttribute attribute, Predicate predicate)
AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ClassLoader classLoader)
AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ClassLoader classLoader, Predicate predicate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handleRequest(HttpServerExchange exchange)
Handle the request.String
toString()
-
-
-
Constructor Detail
-
AccessLogHandler
public AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ClassLoader classLoader)
-
AccessLogHandler
public AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ClassLoader classLoader, Predicate predicate)
-
AccessLogHandler
public AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ExchangeAttribute attribute)
-
AccessLogHandler
public AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ExchangeAttribute attribute, Predicate predicate)
-
-
Method Detail
-
handleRequest
public void handleRequest(HttpServerExchange exchange) throws Exception
Description copied from interface:HttpHandler
Handle the request.- Specified by:
handleRequest
in interfaceHttpHandler
- Parameters:
exchange
- the HTTP request/response exchange- Throws:
Exception
-
-