Class HttpLoggingPolicy
- All Implemented Interfaces:
HttpPipelinePolicy
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttpLoggingPolicy(HttpLogOptions httpLogOptions) Creates an HttpLoggingPolicy with the given log configurations. -
Method Summary
Modifier and TypeMethodDescriptionprocess(HttpPipelineCallContext context, HttpPipelineNextPolicy next) Processes provided request context and invokes the next policy.processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next) Processes provided request context and invokes the next policy synchronously.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.core.http.policy.HttpPipelinePolicy
getPipelinePosition
-
Field Details
-
RETRY_COUNT_CONTEXT
Key forContextto pass request retry count metadata for logging.- See Also:
-
-
Constructor Details
-
HttpLoggingPolicy
Creates an HttpLoggingPolicy with the given log configurations.- Parameters:
httpLogOptions- The HTTP logging configuration options.
-
-
Method Details
-
process
Description copied from interface:HttpPipelinePolicyProcesses provided request context and invokes the next policy.- Specified by:
processin interfaceHttpPipelinePolicy- Parameters:
context- The request context.next- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-
processSync
Description copied from interface:HttpPipelinePolicyProcesses provided request context and invokes the next policy synchronously.- Specified by:
processSyncin interfaceHttpPipelinePolicy- Parameters:
context- The request context.next- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-