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.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);
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)
Deprecated Sets the given allowed header to the default header set that should be logged. |
Http |
addAllowedHttpHeaderName(HttpHeaderName allowedHeaderName)
Sets the given allowed HttpHeaderName 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()
Deprecated
Use getAllowedHttpHeaderNames() instead.
Gets the allowed headers that should be logged. |
Set<Http |
getAllowedHttpHeaderNames()
Gets the allowed HttpHeaderName 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()
Deprecated
Use setRequestLogger(HttpRequestLogger requestLogger) and setResponseLogger(HttpResponseLogger responseLogger) to configure how requests and responses should be logged at a granular level instead.
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)
Deprecated Sets the given allowed headers that should be logged. |
Http |
setAllowedHttpHeaderNames(Set<HttpHeaderName> allowedHttpHeaderNames)
Sets the given allowed HttpHeaderName 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)
Deprecated
Use setRequestLogger(HttpRequestLogger requestLogger) and setResponseLogger(HttpResponseLogger responseLogger) to configure how requests and responses should be logged at a granular level instead.
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
@Deprecated
public HttpLogOptions addAllowedHeaderName(String allowedHeaderName)
Deprecated
Sets the given allowed header to the default header set that should be logged.
With the deprecation of this method, the passed allowedHeaderName
will be converted to an HttpHeaderName using fromString(String name).
Parameters:
Returns:
addAllowedHttpHeaderName
public HttpLogOptions addAllowedHttpHeaderName(HttpHeaderName allowedHeaderName)
Sets the given allowed HttpHeaderName 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:
Returns:
getAllowedHeaderNames
@Deprecated
public Set
Deprecated
Gets the allowed headers that should be logged.
With the deprecation of this method, this will now return a new HashSet each time called where the values are mapped from getCaseSensitiveName().
Returns:
getAllowedHttpHeaderNames
public Set
Gets the allowed HttpHeaderName 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
@Deprecated
public boolean isPrettyPrintBody()
Deprecated
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
@Deprecated
public HttpLogOptions setAllowedHeaderNames(Set
Deprecated
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.
With the deprecation of this method, if allowedHeaderNames
is non-null, this will map the passed allowedHeaderNames
to a set of HttpHeaderName using fromString(String name) on each value in the set.
Parameters:
Returns:
setAllowedHttpHeaderNames
public HttpLogOptions setAllowedHttpHeaderNames(Set
Sets the given allowed HttpHeaderName 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
@Deprecated
public HttpLogOptions setPrettyPrintBody(boolean prettyPrintBody)
Deprecated
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: