Package org.zalando.logbook
Interface Strategy
@API(status=STABLE)
public interface Strategy
A strategy is glue between
Logbook
integrations and the Sink
. The lifecycle of a request-response
pair will invoke methods in the following order:
process(HttpRequest)
write(Precorrelation, HttpRequest, Sink)
process(HttpRequest, HttpResponse)
write(Correlation, HttpRequest, HttpResponse, Sink)
At each of those points in time different options are available, e.g. to defer logging, apply conditions or even modify something. Strategy pattern
-
Method Summary
Modifier and TypeMethodDescriptiondefault HttpRequest
process
(HttpRequest request) This method is being called right before the request body is being buffered.default HttpResponse
process
(HttpRequest request, HttpResponse response) This method is being called right before the response body is being buffered.default void
write
(Correlation correlation, HttpRequest request, HttpResponse response, Sink sink) This method is being called right after the response body was buffered.default void
write
(Precorrelation precorrelation, HttpRequest request, Sink sink) This method is being called right after the response body was buffered.
-
Method Details
-
process
This method is being called right before the request body is being buffered. The primary goal of this method is to decide whether the body should be recorded or not.Defaults to
HttpRequest.withBody()
.- Parameters:
request
- the current request- Returns:
- the given request
- Throws:
IOException
- seeHttpRequest.withBody()
- See Also:
-
write
default void write(Precorrelation precorrelation, HttpRequest request, Sink sink) throws IOException This method is being called right after the response body was buffered. The primary goal of this method is to decide whether and if then how the request is being logged.Options include but are not limited to:
- Log request immediately.
- Defer logging to a later point in time (e.g. when the response becomes available).
- Log request conditionally.
- Log request without body. (Performance penalty for buffering still applies!)
Defaults to delegating to
Sink.write(Precorrelation, HttpRequest)
.- Parameters:
precorrelation
- a preliminarycorrelation
which provides an id to correlate request and response laterrequest
- the current requestsink
- the sink to write to, if needed- Throws:
IOException
- seeSink.write(Precorrelation, HttpRequest)
- See Also:
-
process
This method is being called right before the response body is being buffered. The primary goal of this method is to decide whether the body should be recorded or not. Beware that the response may or may not be a reliable source of information since it was fully processed yet. Any decision whether to buffer the body or not should be made exclusively based on the providedrequest
.Defaults to
HttpResponse.withBody()
.- Parameters:
request
- the current requestresponse
- the current response- Returns:
- the given response
- Throws:
IOException
- seeHttpResponse.withBody()
- See Also:
-
write
default void write(Correlation correlation, HttpRequest request, HttpResponse response, Sink sink) throws IOException This method is being called right after the response body was buffered. The primary goal of this method is to decide whether and if then how the response (and optionally also the request) is being logged.Options include but are not limited to:
- Log response immediately.
- Log response conditionally.
- Log response without body. (Performance penalty for buffering still applies!)
- Log request now, instead of earlier.
- Log request conditionally based on the response.
- Log request without body. (Performance penalty for buffering still applies!)
Defaults to delegating to
Sink.write(Correlation, HttpRequest, HttpResponse)
.- Parameters:
correlation
- a correlation which provides and id (as well as a duration) to correlate request and response laterrequest
- the current requestresponse
- the current responsesink
- the sink to write to, if needed- Throws:
IOException
- seeSink.write(Correlation, HttpRequest, HttpResponse)
- See Also:
-