Logging request activity

In the base configuration, only the handleRequestProcessed method in the DefaultRestDispatchPlugin class performs logging of the REST request activity by default. The method writes the PLLoggingMarker.REST_REQUEST traceability marker to the application server log using the information provided by the method arguments.

PolicyCenter explicitly invokes the handleRequestProcessed method after it finishes writing out the request response. Calling this method after the write operation completes (and the output stream closes) ensures that even if logging adds some amount of server overhead, it does not impact response latency.

Protected logging methods

Class DefaultRestDispatchPlugin contains a number of protected methods for manipulating the information to output to the server log files.

The DefaultRestDispatchPlugin class provides the following protected methods.
logClientError(requestContext, elapsedMs, operationError, serializedResponse)
If there is any issue with REST request itself, the issue generates an error of type ErrorInfo (operationError). The handleRequestProcessed method passes the error to the logClientError method, which, in turn, passes the error to the standardLogResponse method for output to the server log.
logServerError(requestContext, elapsedMs, operationError, serializedResponse)
If there is any issue with the server processing the request, meaning any error in determining the operation handler or an error with the handler executing the request, it generates an error of type ErrorInfo (operationError). The handleRequestProcessed method passes the error to the logServerError method, which, in turn, passes the error to the standardLogResponse method for output to the server log.
logSerializationError(requestContext, elapsedMs, handlerResponse, operationError, serializedResponse)
If the attempt to serialize the request response fails, it generates an error of type ErrorInfo (serializationError). The handleRequestProcessed method passes the error to the logSerializationError method, which, in turn, passes the error to the standardLogResponse method for output to the server log.
logWriteException(requestContext, elapsedMs, handlerResponse, operationError, serializedResponse, serializationError, writeException)
If the attempt to write the request response fails, it is unknown if the client received any part of the response. The failure generates an error of type Throwable (writeException). The handleRequestProcessed method calls the logWriteException method (instead of the standardLogResponse method) to log information about what failed in the write operation.
logSuccessfulResponse(requestContext, elapsedMs, handlerResponse, serializedResponse)
If the result of the REST request is successful, the handleRequestProcessed methods passes the request context, the elapsed time, the handler response, and the serialized response to the logSuccessfulResponse method. This method, in turn, passes this information to the standardLogResponse method for output to the server log.
standardLogResponse(requestContext, elapsedMs, serializedResponse, error)
The other logging methods (all except for the logWriteException method) call the standardLogResponse method to perform the actual work of writing to the server log. This method writes the PLLoggingMarker.REST_REQUEST marker to the server log by default.
In the base configuration, this method logs the following information:
  • path
  • query
  • pathTemplate
  • apiFqn
  • method
  • user
  • status
  • error
  • elapsed time
For examples of log entries for successful and unsuccessful REST requests, see The IRestDispatchPlugin plugin