Class HttpLoggingPolicy

java.lang.Object
com.azure.core.http.policy.HttpLoggingPolicy
All Implemented Interfaces:
HttpPipelinePolicy

public class HttpLoggingPolicy extends Object implements HttpPipelinePolicy
The HttpLoggingPolicy class is an implementation of the HttpPipelinePolicy interface. This policy handles logging of HTTP requests and responses based on the provided HttpLogOptions.

This class is useful when you need to log HTTP traffic for debugging or auditing purposes. It allows you to control the amount of information that is logged, including the URL, headers, and body of requests and responses.

NOTE: Enabling body logging (using the BODY or BODY_AND_HEADERS levels) will buffer the response body into memory even if it is never consumed by your application, possibly impacting performance.

Code sample:

In this example, an HttpLogOptions is created and the log level is set to HttpLogDetailLevel.BODY_AND_HEADERS. This means that the URL, HTTP method, headers, and body content of each request and response will be logged. The HttpLogOptions is then used to create an HttpLoggingPolicy, which can then added to the pipeline.

 HttpLogOptions logOptions = new HttpLogOptions();
 logOptions.setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS);
 HttpLoggingPolicy loggingPolicy = new HttpLoggingPolicy(logOptions);
 
See Also:
  • Field Details

  • Constructor Details

    • HttpLoggingPolicy

      public HttpLoggingPolicy(HttpLogOptions httpLogOptions)
      Creates an HttpLoggingPolicy with the given log configurations.
      Parameters:
      httpLogOptions - The HTTP logging configuration options.
  • Method Details