Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LogLevel Hooks to HttpLogOptions and HttpLoggingPolicy #16088

Merged
merged 26 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
588ca4a
Add functions to HttpLogOptions to determine the log level for reques…
alzimmermsft Oct 8, 2020
0b40786
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Oct 12, 2020
b51dad2
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Oct 14, 2020
9e78ca7
Added configuration for custom HTTP request and HTTP response logging
alzimmermsft Oct 15, 2020
e3b6b3f
Add HttpRequestLogger and HttpResponseLogger interfaces which allows …
alzimmermsft Oct 19, 2020
0633212
Removed options bags classes that were unused prototypes
alzimmermsft Oct 19, 2020
7c21b47
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Oct 21, 2020
5388245
Return HttpResponse when not logging it
alzimmermsft Oct 21, 2020
ec0060c
Remove LogLevel parameter from interface APIs, changed getLogLevel to…
alzimmermsft Oct 21, 2020
a241bba
Javadoc updates
alzimmermsft Oct 21, 2020
f611b73
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Oct 22, 2020
a8cfbc3
Add logger option bag classes to pass information for logging the req…
alzimmermsft Oct 22, 2020
2550458
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Nov 13, 2020
3f091cd
Pull in upstream
alzimmermsft Jan 19, 2021
85795bf
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Feb 2, 2021
7519672
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Apr 5, 2021
80c3bf4
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Apr 27, 2021
6198bbb
Use accessor pattern instead of making API public
alzimmermsft Apr 27, 2021
052ac13
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft May 11, 2021
cd3bbd4
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft May 19, 2021
3f1a5b6
Merge branch 'master' into AzCore_AddHttpLoggingHooks
alzimmermsft Jun 15, 2021
95813cc
Merge branch 'main' into AzCore_AddHttpLoggingHooks
alzimmermsft Jun 30, 2021
43a0fb8
Merge branch 'main' into AzCore_AddHttpLoggingHooks
alzimmermsft Jul 12, 2021
381ea82
Merge branch 'AzCore_AddHttpLoggingHooks' of github.com:alzimmermsft/…
alzimmermsft Jul 12, 2021
68208e2
Merge branch 'main' into AzCore_AddHttpLoggingHooks
alzimmermsft Jul 15, 2021
f907d05
Rename Options to Context
alzimmermsft Jul 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

package com.azure.core.http.policy;

import com.azure.core.util.CoreUtils;
import com.azure.core.http.HttpPipelineCallContext;
import com.azure.core.http.HttpResponse;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;

import java.time.Duration;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand All @@ -22,6 +26,11 @@ public class HttpLogOptions {
private Set<String> allowedHeaderNames;
private Set<String> allowedQueryParamNames;
private boolean prettyPrintBody;

private LogLevel defaultLogLevel;
private HttpRequestLogger requestLogger;
private HttpResponseLogger responseLogger;

private final ClientLogger logger = new ClientLogger(HttpLogOptions.class);

private static final int MAX_APPLICATION_ID_LENGTH = 24;
Expand Down Expand Up @@ -96,10 +105,9 @@ public Set<String> getAllowedHeaderNames() {
*
* <p>
* This method sets the provided header names to be the whitelisted header names which will be logged for all HTTP
* requests and responses, overwriting any previously configured headers, including the default set. Additionally,
* users can use {@link HttpLogOptions#addAllowedHeaderName(String)} or
* {@link HttpLogOptions#getAllowedHeaderNames()} to add or remove more headers names to the existing set of
* allowed header names.
* requests and responses, overwriting any previously configured headers. Additionally, users can use {@link
* HttpLogOptions#addAllowedHeaderName(String)} or {@link HttpLogOptions#getAllowedHeaderNames()} to add or remove
* more headers names to the existing set of allowed header names.
* </p>
*
* @param allowedHeaderNames The list of whitelisted header names from the user.
Expand Down Expand Up @@ -202,12 +210,92 @@ public boolean isPrettyPrintBody() {
/**
* Sets flag to allow pretty printing of message bodies.
*
* @param prettyPrintBody If true, pretty prints message bodies when logging. If the detailLevel does not
* include body logging, this flag does nothing.
* @param prettyPrintBody If true, pretty prints message bodies when logging. If the detailLevel does not include
* body logging, this flag does nothing.
* @return The updated HttpLogOptions object.
*/
public HttpLogOptions setPrettyPrintBody(boolean prettyPrintBody) {
this.prettyPrintBody = prettyPrintBody;
return this;
}

/**
* Gets the {@link LogLevel} used by default when logging requests and responses.
* <p>
* {@link HttpRequestLogger#getLogLevel(LogLevel, HttpPipelineCallContext)} and {@link
* HttpResponseLogger#getLogLevel(LogLevel, HttpResponse, Duration)} can be used to set the {@link LogLevel} for
* each request and response being logged.
* <p>
* By default {@link LogLevel#INFORMATIONAL} is used.
*
* @return The {@link LogLevel} used by default when logging requests and responses.
*/
public LogLevel getDefaultLogLevel() {
return defaultLogLevel;
}

/**
* Sets the {@link LogLevel} used by default when logging requests and responses.
* <p>
* {@link HttpRequestLogger#getLogLevel(LogLevel, HttpPipelineCallContext)} and {@link
* HttpResponseLogger#getLogLevel(LogLevel, HttpResponse, Duration)} can be used to set the {@link LogLevel} for
* each request and response being logged.
* <p>
* By default {@link LogLevel#INFORMATIONAL} is used.
*
* @param defaultLogLevel The default log level.
* @return The updated HttpLogOptions object.
*/
public HttpLogOptions setDefaultLogLevel(LogLevel defaultLogLevel) {
this.defaultLogLevel = defaultLogLevel;
return this;
}

/**
* Gets the {@link HttpRequestLogger} that will be used to log requests.
* <p>
* A default logger will be used if one isn't supplied.
*
* @return The {@link HttpRequestLogger} that will be used to log requests.
*/
public HttpRequestLogger getRequestLogger() {
return requestLogger;
}

/**
* Sets the {@link HttpRequestLogger} that will be used to log requests.
* <p>
* A default logger will be used if one isn't supplied.
*
* @param requestLogger The {@link HttpRequestLogger} that will be used to log requests.
* @return The updated HttpLogOptions object.
*/
public HttpLogOptions setRequestLogger(HttpRequestLogger requestLogger) {
this.requestLogger = requestLogger;
return this;
}

/**
* Gets the {@link HttpResponseLogger} that will be used to log responses.
* <p>
* A default logger will be used if one isn't supplied.
*
* @return The {@link HttpResponseLogger} that will be used to log responses.
*/
public HttpResponseLogger getResponseLogger() {
return responseLogger;
}

/**
* Sets the {@link HttpResponseLogger} that will be used to log responses.
* <p>
* A default logger will be sued if one isn't supplied.
*
* @param responseLogger The {@link HttpResponseLogger} that will be used to log responses.
* @return The updated HttpLogOptions object.
*/
public HttpLogOptions setResponseLogger(HttpResponseLogger responseLogger) {
this.responseLogger = responseLogger;
return this;
}
}
Loading