11package io .avaje .http .client ;
22
3- import org .slf4j .Logger ;
4- import org .slf4j .LoggerFactory ;
5-
3+ import java .lang .System .Logger .Level ;
64import java .net .http .HttpHeaders ;
75import java .net .http .HttpRequest ;
86import java .net .http .HttpResponse ;
119import java .util .Set ;
1210
1311/**
14- * Logs request and response details for debug logging purposes.
12+ * Logs request and response details for debug logging purposes using <code>System.Logger</code>.
13+ * <p>
14+ * This implementation logs the request and response with the same single logging entry
15+ * rather than separate logging of the request and response.
1516 * <p>
16- * This implementation logs the request and response with the same
17- * single logging entry rather than separate logging of the request
18- * and response.
17+ * With logging level set to {@code DEBUG} for {@code io.avaje.http.client.RequestLogger} the
18+ * request and response are logged as a summary with response status and time.
1919 * <p>
20- * With logging level set to {@code DEBUG} for
21- * {@code io.avaje.http.client.RequestLogger} the request and response
22- * are logged as a summary with response status and time.
20+ * Set the logging level to {@code TRACE} to include the request and response headers and body
21+ * payloads with truncation for large bodies.
2322 * <p>
24- * Set the logging level to {@code TRACE} to include the request
25- * and response headers and body payloads with truncation for large
26- * bodies .
23+ * Using System.Logger, messages by default go to JUL (Java Util Logging) unless a provider
24+ * is registered. We can use <em>io.avaje:avaje-slf4j-jpl</em> to have System.Logger
25+ * messages go to <em>slf4j-api</em> .
2726 */
2827public class RequestLogger implements RequestListener {
2928
30- private static final Logger log = LoggerFactory .getLogger (RequestLogger . class );
29+ private static final System . Logger log = System .getLogger ("io.avaje.http.client.RequestLogger" );
3130
3231 private final String delimiter ;
3332
@@ -47,7 +46,7 @@ public RequestLogger(String delimiter) {
4746
4847 @ Override
4948 public void response (Event event ) {
50- if (log .isDebugEnabled ( )) {
49+ if (log .isLoggable ( Level . DEBUG )) {
5150 final HttpResponse <?> response = event .response ();
5251 final HttpRequest request = response .request ();
5352 long micros = event .responseTimeMicros ();
@@ -58,13 +57,13 @@ public void response(Event event) {
5857 .append (" uri:" ).append (event .uri ())
5958 .append (" timeMicros:" ).append (micros );
6059
61- if (log .isTraceEnabled ( )) {
60+ if (log .isLoggable ( Level . TRACE )) {
6261 headers (sb , "req-head: " , request .headers ());
6362 body (sb , "req-body: " , event .requestBody ());
6463 headers (sb , "res-head: " , response .headers ());
6564 body (sb , "res-body: " , event .responseBody ());
6665 }
67- log .debug ( sb .toString ());
66+ log .log ( Level . DEBUG , sb .toString ());
6867 }
6968 }
7069
0 commit comments