Package com.shri.restinpeace.interceptor
Class LoggingInterceptor
java.lang.Object
com.shri.restinpeace.interceptor.LoggingInterceptor
- All Implemented Interfaces:
RequestInterceptor
Pre-built interceptor that logs a line before a request goes out and
another when its response comes back, including the elapsed time. Sends to
System.out::println by default; pass a Consumer to route
lines to a real logger instead, without pulling a logging framework into
this library's own dependencies.-
Constructor Summary
ConstructorsConstructorDescriptionLogs toSystem.out.LoggingInterceptor(Consumer<String> sink) Logs to a custom sink instead ofSystem.out. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterResponse(RequestContext context, int status, Object body) Called once the response is back.voidbeforeRequest(RequestContext context) Called before the request is sent.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.shri.restinpeace.interceptor.RequestInterceptor
shortCircuit
-
Constructor Details
-
LoggingInterceptor
public LoggingInterceptor()Logs toSystem.out. -
LoggingInterceptor
Logs to a custom sink instead ofSystem.out.- Parameters:
sink- receives each log line, e.g. a logger method reference
-
-
Method Details
-
beforeRequest
Description copied from interface:RequestInterceptorCalled before the request is sent. Can add headers viaRequestContext.addHeader(java.lang.String, java.lang.String), or abort the call by throwing.- Specified by:
beforeRequestin interfaceRequestInterceptor- Parameters:
context- the request being made
-
afterResponse
Description copied from interface:RequestInterceptorCalled once the response is back.- Specified by:
afterResponsein interfaceRequestInterceptor- Parameters:
context- the request that was madestatus- the HTTP response status codebody- the response body - aString, a deserialized object, ornullfor avoid-returning method
-