-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding HttpLogOptions for Logging improvements (#5688)
- Loading branch information
Showing
29 changed files
with
301 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/HttpLogOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.http.policy; | ||
|
||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* The log configurations for HTTP messages. | ||
*/ | ||
public class HttpLogOptions { | ||
private HttpLogDetailLevel logLevel; | ||
private Set<String> allowedHeaderNames; | ||
private Set<String> allowedQueryParamNames; | ||
|
||
public HttpLogOptions() { | ||
logLevel = HttpLogDetailLevel.NONE; | ||
allowedHeaderNames = new HashSet<>(); | ||
allowedQueryParamNames = new HashSet<>(); | ||
} | ||
|
||
/** | ||
* Gets the level of detail to log on HTTP messages. | ||
* | ||
* @return The {@link HttpLogDetailLevel}. | ||
*/ | ||
public HttpLogDetailLevel getLogLevel() { | ||
return logLevel; | ||
} | ||
|
||
/** | ||
* Sets the level of detail to log on Http messages. | ||
* | ||
* <p> If logLevel is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.</p> | ||
* | ||
* @param logLevel The {@link HttpLogDetailLevel}. | ||
* @return The updated HttpLogOptions object. | ||
*/ | ||
public HttpLogOptions setLogLevel(final HttpLogDetailLevel logLevel) { | ||
this.logLevel = logLevel == null ? HttpLogDetailLevel.NONE : logLevel; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the whitelisted headers that should be logged. | ||
* | ||
* @return The list of whitelisted headers. | ||
*/ | ||
public Set<String> getAllowedHeaderNames() { | ||
return allowedHeaderNames; | ||
} | ||
|
||
/** | ||
* Sets the given whitelisted headers that should be logged. | ||
* | ||
* @param allowedHeaderNames The list of whitelisted header names from the user. | ||
* @return The updated HttpLogOptions object. | ||
* @throws NullPointerException If {@code allowedHeaderNames} is {@code null}. | ||
*/ | ||
public HttpLogOptions setAllowedHeaderNames(final Set<String> allowedHeaderNames) { | ||
this.allowedHeaderNames = allowedHeaderNames; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the given whitelisted header that should be logged. | ||
* | ||
* @param allowedHeaderName The whitelisted header name from the user. | ||
* @return The updated HttpLogOptions object. | ||
* @throws NullPointerException If {@code allowedHeaderName} is {@code null}. | ||
*/ | ||
public HttpLogOptions addAllowedHeaderName(final String allowedHeaderName) { | ||
Objects.requireNonNull(allowedHeaderName); | ||
this.allowedHeaderNames.add(allowedHeaderName); | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the whitelisted query parameters. | ||
* | ||
* @return The list of whitelisted query parameters. | ||
*/ | ||
public Set<String> getAllowedQueryParamNames() { | ||
return allowedQueryParamNames; | ||
} | ||
|
||
/** | ||
* Sets the given whitelisted query params to be displayed in the logging info. | ||
* | ||
* @param allowedQueryParamNames The list of whitelisted query params from the user. | ||
* @return The updated HttpLogOptions object. | ||
*/ | ||
public HttpLogOptions setAllowedQueryParamNames(final Set<String> allowedQueryParamNames) { | ||
this.allowedQueryParamNames = allowedQueryParamNames; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the given whitelisted query param that should be logged. | ||
* | ||
* @param allowedQueryParamName The whitelisted query param name from the user. | ||
* @return The updated HttpLogOptions object. | ||
* @throws NullPointerException If {@code allowedQueryParamName} is {@code null}. | ||
*/ | ||
public HttpLogOptions addAllowedQueryParamName(final String allowedQueryParamName) { | ||
this.allowedQueryParamNames.add(allowedQueryParamName); | ||
return this; | ||
} | ||
} |
Oops, something went wrong.