logResult

Description

Logs the response.

See logRequest for the general description how these directives work.

Use logRequest for logging the request, or logRequestResult for logging both.

Example

// logs result with "get-user"
final Route routeBasicLogResult = get(() ->
  logResult("get-user", () -> complete("logged")));

// logs result with "get-user" as Info
final Route routeBasicLogResultAsInfo = get(() ->
  logResult("get-user", InfoLevel(), () -> complete("logged")));

// logs the result and the rejections as LogEntry
Function<HttpResponse, LogEntry> showSuccessAsInfo = (response) ->
  LogEntry.create(String.format("Response code '%d'", response.status().intValue()),
    InfoLevel());

Function<List<Rejection>, LogEntry> showRejectionAsInfo = (rejections) ->
  LogEntry.create(
    rejections
      .stream()
      .map(rejection -> rejection.toString())
      .collect(Collectors.joining(", ")),
    InfoLevel());

final Route routeUsingFunction = get(() ->
  logResult(showSuccessAsInfo, showRejectionAsInfo, () -> complete("logged")));
// tests:
testRoute(routeBasicLogResult).run(HttpRequest.GET("/"))
  .assertEntity("logged");
The source code for this page can be found here.