logRequest
Description
Logs the request. The directive is available with the following parameters:
- A marker to prefix each log message with.
- A log level.
- A function that creates a
LogEntry
from theHttpRequest
Use logResult
for logging the response, or logRequestResult
for logging both.
Example
// logs request with "get-user"
final Route routeBasicLogRequest = get(() ->
logRequest("get-user", () -> complete("logged")));
// logs request with "get-user" as Info
final Route routeBasicLogRequestAsInfo = get(() ->
logRequest("get-user", InfoLevel(), () -> complete("logged")));
// logs just the request method at info level
Function<HttpRequest, LogEntry> requestMethodAsInfo = (request) ->
LogEntry.create(request.method().name(), InfoLevel());
final Route routeUsingFunction = get(() ->
logRequest(requestMethodAsInfo, () -> complete("logged")));
// tests:
testRoute(routeBasicLogRequest).run(HttpRequest.GET("/"))
.assertEntity("logged");