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)
-
Method Summary
Modifier and Type Method Description default 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 toHttpRequest.withBody()
.- Parameters:
request
- the current request- Returns:
- the given request
- Throws:
java.io.IOException
- seeHttpRequest.withBody()
- See Also:
HttpRequest.withBody()
,HttpRequest.withoutBody()
-
write
default void write(Precorrelation precorrelation, HttpRequest request, Sink sink) throws java.io.IOExceptionThis 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!)
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:
java.io.IOException
- seeSink.write(Precorrelation, HttpRequest)
- See Also:
Sink.write(Precorrelation, HttpRequest)
-
process
default HttpResponse process(HttpRequest request, HttpResponse response) throws java.io.IOExceptionThis 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 toHttpResponse.withBody()
.- Parameters:
request
- the current requestresponse
- the current response- Returns:
- the given response
- Throws:
java.io.IOException
- seeHttpResponse.withBody()
- See Also:
HttpResponse.withBody()
,HttpResponse.withoutBody()
-
write
default void write(Correlation correlation, HttpRequest request, HttpResponse response, Sink sink) throws java.io.IOExceptionThis 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!)
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:
java.io.IOException
- seeSink.write(Correlation, HttpRequest, HttpResponse)
- See Also:
Sink.write(Correlation, HttpRequest, HttpResponse)
,Sink.writeBoth(Correlation, HttpRequest, HttpResponse)
-