HttpLogOptions Class
- java.
lang. Object - com.
azure. core. http. policy. HttpLogOptions
- com.
public class HttpLogOptions
The 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.setAllowedHeaderNames(new HashSet<>(Arrays.asList("Date", "x-ms-request-id")));
logOptions.setAllowedQueryParamNames(new HashSet<>(Arrays.asList("api-version")));
logOptions.setPrettyPrintBody(true);
HttpLoggingPolicy loggingPolicy = new HttpLoggingPolicy(logOptions);
Constructor Summary
Constructor | Description |
---|---|
HttpLogOptions() |
Creates a new instance that does not log any information about HTTP requests or responses. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Http |
addAllowedHeaderName(String allowedHeaderName)
Sets the given allowed header to the default header set that should be logged. |
Http |
addAllowedQueryParamName(String allowedQueryParamName)
Sets the given allowed query param that should be logged. |
Http |
disableRedactedHeaderLogging(boolean disableRedactedHeaderLogging)
Sets the flag that controls if header names which value is redacted should be logged. |
Set<String> |
getAllowedHeaderNames()
Gets the allowed headers that should be logged. |
Set<String> |
getAllowedQueryParamNames()
Gets the allowed query parameters. |
String |
getApplicationId()
Deprecated
Use ClientOptions to configure
applicationId .
Gets the application specific id. |
Http |
getLogLevel()
Gets the level of detail to log on HTTP messages. |
Http |
getRequestLogger()
Gets the HttpRequestLogger that will be used to log HTTP requests. |
Http |
getResponseLogger()
Gets the HttpResponseLogger that will be used to log HTTP responses. |
boolean |
isPrettyPrintBody()
Gets flag to allow pretty printing of message bodies. |
boolean |
isRedactedHeaderLoggingDisabled()
Gets the flag that controls if header names with redacted values should be logged. |
Http |
setAllowedHeaderNames(Set<String> allowedHeaderNames)
Sets the given allowed headers that should be logged. |
Http |
setAllowedQueryParamNames(Set<String> allowedQueryParamNames)
Sets the given allowed query params to be displayed in the logging info. |
Http |
setApplicationId(String applicationId)
Deprecated
Use ClientOptions to configure
applicationId .
Sets the custom application specific id supplied by the user of the client library. |
Http |
setLogLevel(HttpLogDetailLevel logLevel)
Sets the level of detail to log on Http messages. |
Http |
setPrettyPrintBody(boolean prettyPrintBody)
Sets flag to allow pretty printing of message bodies. |
Http |
setRequestLogger(HttpRequestLogger requestLogger)
Sets the HttpRequestLogger that will be used to log HTTP requests. |
Http |
setResponseLogger(HttpResponseLogger responseLogger)
Sets the HttpResponseLogger that will be used to log HTTP responses. |
Methods inherited from java.lang.Object
Constructor Details
HttpLogOptions
public HttpLogOptions()
Creates a new instance that does not log any information about HTTP requests or responses.
Method Details
addAllowedHeaderName
public HttpLogOptions addAllowedHeaderName(String allowedHeaderName)
Sets the given allowed header to the default header set that should be logged.
Parameters:
Returns:
addAllowedQueryParamName
public HttpLogOptions addAllowedQueryParamName(String allowedQueryParamName)
Sets the given allowed query param that should be logged.
Parameters:
Returns:
disableRedactedHeaderLogging
public HttpLogOptions disableRedactedHeaderLogging(boolean 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 logLevel) for details. Defaults to `false` - redacted header names are logged.
Parameters:
redactedHeaders
property.
Returns:
getAllowedHeaderNames
public Set
Gets the allowed headers that should be logged.
Returns:
getAllowedQueryParamNames
public Set
Gets the allowed query parameters.
Returns:
getApplicationId
@Deprecated
public String getApplicationId()
Deprecated
applicationId
.
Gets the application specific id.
Returns:
getLogLevel
public HttpLogDetailLevel getLogLevel()
Gets the level of detail to log on HTTP messages.
Returns:
getRequestLogger
public HttpRequestLogger getRequestLogger()
Gets the HttpRequestLogger that will be used to log HTTP requests.
A default HttpRequestLogger will be used if one isn't supplied.
Returns:
getResponseLogger
public HttpResponseLogger getResponseLogger()
Gets the HttpResponseLogger that will be used to log HTTP responses.
A default HttpResponseLogger will be used if one isn't supplied.
Returns:
isPrettyPrintBody
public boolean isPrettyPrintBody()
Gets flag to allow pretty printing of message bodies.
Returns:
isRedactedHeaderLoggingDisabled
public boolean isRedactedHeaderLoggingDisabled()
Gets the flag that controls if header names with redacted values should be logged.
Returns:
setAllowedHeaderNames
public HttpLogOptions setAllowedHeaderNames(Set
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 allowedHeaderName) or getAllowedHeaderNames() to add or remove more headers names to the existing set of allowed header names.
Parameters:
Returns:
setAllowedQueryParamNames
public HttpLogOptions setAllowedQueryParamNames(Set
Sets the given allowed query params to be displayed in the logging info.
Parameters:
Returns:
setApplicationId
@Deprecated
public HttpLogOptions setApplicationId(String applicationId)
Deprecated
applicationId
.
Sets the custom application specific id supplied by the user of the client library.
Parameters:
Returns:
setLogLevel
public HttpLogOptions setLogLevel(HttpLogDetailLevel logLevel)
Sets the level of detail to log on Http messages.
If logLevel is not provided, default value of NONE is set.
Parameters:
Returns:
setPrettyPrintBody
public HttpLogOptions setPrettyPrintBody(boolean prettyPrintBody)
Sets flag to allow pretty printing of message bodies.
Parameters:
Returns:
setRequestLogger
public HttpLogOptions setRequestLogger(HttpRequestLogger requestLogger)
Sets the HttpRequestLogger that will be used to log HTTP requests.
A default HttpRequestLogger will be used if one isn't supplied.
Parameters:
Returns:
setResponseLogger
public HttpLogOptions setResponseLogger(HttpResponseLogger responseLogger)
Sets the HttpResponseLogger that will be used to log HTTP responses.
A default HttpResponseLogger will be used if one isn't supplied.
Parameters:
Returns:
Applies to
Azure SDK for Java