Package com.metronome.api.core.http
Class LoggingHttpClient
-
- All Implemented Interfaces:
-
com.metronome.api.core.http.HttpClient,java.lang.AutoCloseable
public final class LoggingHttpClient implements HttpClient
A wrapper HttpClient around httpClient that logs request and response information.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classLoggingHttpClient.BuilderA builder for LoggingHttpClient.
-
Field Summary
Fields Modifier and Type Field Description private final HttpClienthttpClientprivate final SortedSet<String>redactedHeadersprivate final Clockclockprivate final LogLevellevel
-
Method Summary
Modifier and Type Method Description final HttpClienthttpClient()The underlying HttpClient for making requests. final SortedSet<String>redactedHeaders()Sensitive headers to redact from logs. final Clockclock()The clock to use for measuring request and response durations. final LogLevellevel()The log level to use. HttpResponseexecute(HttpRequest request, RequestOptions requestOptions)CompletableFuture<HttpResponse>executeAsync(HttpRequest request, RequestOptions requestOptions)Unitclose()Overridden from AutoCloseable to not have a checked exception in its signature. final LoggingHttpClient.BuildertoBuilder()final static LoggingHttpClient.Builderbuilder()Returns a mutable builder for constructing an instance of LoggingHttpClient. -
-
Method Detail
-
httpClient
final HttpClient httpClient()
The underlying HttpClient for making requests.
-
redactedHeaders
final SortedSet<String> redactedHeaders()
Sensitive headers to redact from logs.
Defaults to
Set.of("authorization", "api-key", "x-api-key", "cookie", "set-cookie").
-
clock
final Clock clock()
The clock to use for measuring request and response durations.
This is primarily useful for using a fake clock in tests.
Defaults to Clock.systemUTC.
-
level
final LogLevel level()
The log level to use.
Pass LogLevel.fromEnv to read from environment variables.
-
execute
HttpResponse execute(HttpRequest request, RequestOptions requestOptions)
-
executeAsync
CompletableFuture<HttpResponse> executeAsync(HttpRequest request, RequestOptions requestOptions)
-
close
Unit close()
Overridden from AutoCloseable to not have a checked exception in its signature.
-
toBuilder
final LoggingHttpClient.Builder toBuilder()
-
builder
final static LoggingHttpClient.Builder builder()
Returns a mutable builder for constructing an instance of LoggingHttpClient.
The following fields are required:
.httpClient() .level()
-
-
-
-