HttpLoggingPolicy Class

  • java.lang.Object
    • com.azure.core.http.policy.HttpLoggingPolicy

Implements

public class HttpLoggingPolicy
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);

Field Summary

Modifier and Type Field and Description
static final String RETRY_COUNT_CONTEXT

Key for Context to pass request retry count metadata for logging.

Constructor Summary

Constructor Description
HttpLoggingPolicy(HttpLogOptions httpLogOptions)

Creates an HttpLoggingPolicy with the given log configurations.

Method Summary

Modifier and Type Method and Description
Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next)

Processes provided request context and invokes the next policy.

HttpResponse processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next)

Processes provided request context and invokes the next policy synchronously.

Methods inherited from java.lang.Object

Field Details

RETRY_COUNT_CONTEXT

public static final String RETRY_COUNT_CONTEXT

Key for Context to pass request retry count metadata for logging.

Constructor Details

HttpLoggingPolicy

public HttpLoggingPolicy(HttpLogOptions httpLogOptions)

Creates an HttpLoggingPolicy with the given log configurations.

Parameters:

httpLogOptions - The HTTP logging configuration options.

Method Details

process

public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next)

Processes provided request context and invokes the next policy.

Parameters:

context
next

processSync

public HttpResponse processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next)

Processes provided request context and invokes the next policy synchronously.

Parameters:

context
next

Applies to