Class HttpLogOptions
HttpLogOptions class provides configuration options for HTTP logging. This includes setting the log level,
specifying allowed header names and query parameters for logging, and controlling whether to pretty print the body
of HTTP messages.
This class is useful when you need to control the amount of information that is logged during the execution of HTTP requests and responses. It allows you to specify the log level, which determines the amount of detail included in the logs (such as the URL, headers, and body of requests and responses).
Code sample:
In this example, the 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 allowed header names and query parameters for logging are also specified, and pretty printing of the body is enabled.
The HttpLogOptions is then used to create an HttpLoggingPolicy, which can then be added to the pipeline.
HttpLogOptions logOptions = new HttpLogOptions();
logOptions.setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS);
logOptions.setAllowedHttpHeaderNames(new HashSet<>(Arrays.asList(HttpHeaderName.DATE,
HttpHeaderName.X_MS_REQUEST_ID)));
logOptions.setAllowedQueryParamNames(new HashSet<>(Arrays.asList("api-version")));
HttpLoggingPolicy loggingPolicy = new HttpLoggingPolicy(logOptions);
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance that does not log any information about HTTP requests or responses. -
Method Summary
Modifier and TypeMethodDescriptionaddAllowedHeaderName(String allowedHeaderName) Deprecated.addAllowedHttpHeaderName(HttpHeaderName allowedHeaderName) Sets the given allowedHttpHeaderNameto the default header set that should be logged.addAllowedQueryParamName(String allowedQueryParamName) Sets the given allowed query param that should be logged.disableRedactedHeaderLogging(boolean disableRedactedHeaderLogging) Sets the flag that controls if header names which value is redacted should be logged.Deprecated.UsegetAllowedHttpHeaderNames()instead.Gets the allowedHttpHeaderNamesthat should be logged.Gets the allowed query parameters.Deprecated.UseClientOptionsto configureapplicationId.Gets the level of detail to log on HTTP messages.Gets theHttpRequestLoggerthat will be used to log HTTP requests.Gets theHttpResponseLoggerthat will be used to log HTTP responses.booleanDeprecated.UsesetRequestLogger(HttpRequestLogger)andsetResponseLogger(HttpResponseLogger)to configure how requests and responses should be logged at a granular level instead.booleanGets the flag that controls if header names with redacted values should be logged.setAllowedHeaderNames(Set<String> allowedHeaderNames) Deprecated.UsesetAllowedHttpHeaderNames(Set)instead.setAllowedHttpHeaderNames(Set<HttpHeaderName> allowedHttpHeaderNames) Sets the given allowedHttpHeaderNamesthat should be logged.setAllowedQueryParamNames(Set<String> allowedQueryParamNames) Sets the given allowed query params to be displayed in the logging info.setApplicationId(String applicationId) Deprecated.UseClientOptionsto configureapplicationId.setLogLevel(HttpLogDetailLevel logLevel) Sets the level of detail to log on Http messages.setPrettyPrintBody(boolean prettyPrintBody) Deprecated.UsesetRequestLogger(HttpRequestLogger)andsetResponseLogger(HttpResponseLogger)to configure how requests and responses should be logged at a granular level instead.setRequestLogger(HttpRequestLogger requestLogger) Sets theHttpRequestLoggerthat will be used to log HTTP requests.setResponseLogger(HttpResponseLogger responseLogger) Sets theHttpResponseLoggerthat will be used to log HTTP responses.
-
Constructor Details
-
HttpLogOptions
public HttpLogOptions()Creates a new instance that does not log any information about HTTP requests or responses.
-
-
Method Details
-
getLogLevel
Gets the level of detail to log on HTTP messages.- Returns:
- The
HttpLogDetailLevel.
-
setLogLevel
Sets the level of detail to log on Http messages.If logLevel is not provided, default value of
HttpLogDetailLevel.NONEis set.- Parameters:
logLevel- TheHttpLogDetailLevel.- Returns:
- The updated HttpLogOptions object.
-
getAllowedHeaderNames
Deprecated.UsegetAllowedHttpHeaderNames()instead.Gets the allowed headers that should be logged.With the deprecation of this method, this will now return a new
HashSeteach time called where the values are mapped fromHttpHeaderName.getCaseSensitiveName().- Returns:
- The list of allowed headers.
-
getAllowedHttpHeaderNames
Gets the allowedHttpHeaderNamesthat should be logged.- Returns:
- The list of allowed
HttpHeaderNames.
-
setAllowedHeaderNames
Deprecated.UsesetAllowedHttpHeaderNames(Set)instead.Sets the given allowed headers that should be logged.This method sets the provided header names to be the allowed header names which will be logged for all HTTP requests and responses, overwriting any previously configured headers. Additionally, users can use
addAllowedHeaderName(String)orgetAllowedHeaderNames()to add or remove more headers names to the existing set of allowed header names.With the deprecation of this method, if
allowedHeaderNamesis non-null, this will map the passedallowedHeaderNamesto a set ofHttpHeaderNameusingHttpHeaderName.fromString(String)on each value in the set.- Parameters:
allowedHeaderNames- The list of allowed header names.- Returns:
- The updated HttpLogOptions object.
-
setAllowedHttpHeaderNames
Sets the given allowedHttpHeaderNamesthat should be logged.This method sets the provided header names to be the allowed header names which will be logged for all HTTP requests and responses, overwriting any previously configured headers. Additionally, users can use
addAllowedHeaderName(String)orgetAllowedHeaderNames()to add or remove more headers names to the existing set of allowed header names.- Parameters:
allowedHttpHeaderNames- The list of allowedHttpHeaderNames.- Returns:
- The updated HttpLogOptions object.
-
addAllowedHeaderName
Deprecated.UseaddAllowedHttpHeaderName(HttpHeaderName)instead.Sets the given allowed header to the default header set that should be logged.With the deprecation of this method, the passed
allowedHeaderNamewill be converted to anHttpHeaderNameusingHttpHeaderName.fromString(String).- Parameters:
allowedHeaderName- The allowed header name.- Returns:
- The updated HttpLogOptions object.
- Throws:
NullPointerException- IfallowedHeaderNameisnull.
-
addAllowedHttpHeaderName
Sets the given allowedHttpHeaderNameto the default header set that should be logged.- Parameters:
allowedHeaderName- The allowedHttpHeaderName.- Returns:
- The updated HttpLogOptions object.
- Throws:
NullPointerException- IfallowedHeaderNameisnull.
-
getAllowedQueryParamNames
Gets the allowed query parameters.- Returns:
- The list of allowed query parameters.
-
setAllowedQueryParamNames
Sets the given allowed query params to be displayed in the logging info.- Parameters:
allowedQueryParamNames- The list of allowed query params from the user.- Returns:
- The updated HttpLogOptions object.
-
addAllowedQueryParamName
Sets the given allowed query param that should be logged.- Parameters:
allowedQueryParamName- The allowed query param name from the user.- Returns:
- The updated HttpLogOptions object.
- Throws:
NullPointerException- IfallowedQueryParamNameisnull.
-
getApplicationId
Deprecated.UseClientOptionsto configureapplicationId.Gets the application specific id.- Returns:
- The application specific id.
-
setApplicationId
Deprecated.UseClientOptionsto configureapplicationId.Sets the custom application specific id supplied by the user of the client library.- Parameters:
applicationId- The user specified application id.- Returns:
- The updated HttpLogOptions object.
- Throws:
IllegalArgumentException- IfapplicationIdcontains spaces or is larger than 24 characters in length.
-
isPrettyPrintBody
Deprecated.UsesetRequestLogger(HttpRequestLogger)andsetResponseLogger(HttpResponseLogger)to configure how requests and responses should be logged at a granular level instead.Gets flag to allow pretty printing of message bodies.- Returns:
- true if pretty printing of message bodies is allowed.
-
setPrettyPrintBody
Deprecated.UsesetRequestLogger(HttpRequestLogger)andsetResponseLogger(HttpResponseLogger)to configure how requests and responses should be logged at a granular level instead.Sets flag to allow pretty printing of message bodies.- Parameters:
prettyPrintBody- If true, pretty prints message bodies when logging. If the detailLevel does not include body logging, this flag does nothing.- Returns:
- The updated HttpLogOptions object.
-
getRequestLogger
Gets theHttpRequestLoggerthat will be used to log HTTP requests.A default
HttpRequestLoggerwill be used if one isn't supplied.- Returns:
- The
HttpRequestLoggerthat will be used to log HTTP requests.
-
setRequestLogger
Sets theHttpRequestLoggerthat will be used to log HTTP requests.A default
HttpRequestLoggerwill be used if one isn't supplied.- Parameters:
requestLogger- TheHttpRequestLoggerthat will be used to log HTTP requests.- Returns:
- The updated HttpLogOptions object.
-
getResponseLogger
Gets theHttpResponseLoggerthat will be used to log HTTP responses.A default
HttpResponseLoggerwill be used if one isn't supplied.- Returns:
- The
HttpResponseLoggerthat will be used to log HTTP responses.
-
setResponseLogger
Sets theHttpResponseLoggerthat will be used to log HTTP responses.A default
HttpResponseLoggerwill be used if one isn't supplied.- Parameters:
responseLogger- TheHttpResponseLoggerthat will be used to log HTTP responses.- Returns:
- The updated HttpLogOptions object.
-
disableRedactedHeaderLogging
Sets the flag that controls if header names which value is redacted should be logged.Applies only if logging request and response headers is enabled. See
setLogLevel(HttpLogDetailLevel)for details. Defaults to false - redacted header names are logged.- Parameters:
disableRedactedHeaderLogging- If true, redacted header names are not logged. Otherwise, they are logged as a comma separated list under redactedHeaders property.- Returns:
- The updated HttpLogOptions object.
-
isRedactedHeaderLoggingDisabled
public boolean isRedactedHeaderLoggingDisabled()Gets the flag that controls if header names with redacted values should be logged.- Returns:
- true if header names with redacted values should be logged.
-
addAllowedHttpHeaderName(HttpHeaderName)instead.