Skip to content

Commit 7ccf720

Browse files
committed
In-progress logging refactor
1 parent 5a4f9fc commit 7ccf720

File tree

7 files changed

+26
-34
lines changed

7 files changed

+26
-34
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl,
9393
if (((AbstractClientApplicationBase) msalRequest.application()).azureRegion() == null
9494
&& ((AbstractClientApplicationBase) msalRequest.application()).autoDetectRegion()
9595
&& detectedRegion != null) {
96-
log.debug(String.format("Region autodetection found %s, this region will be used for future calls.", detectedRegion));
96+
log.debug("Region autodetection found {}, this region will be used for future calls.", detectedRegion);
9797

9898
((AbstractClientApplicationBase) msalRequest.application()).azureRegion = detectedRegion;
9999
host = getRegionalizedHost(authorityUrl.getHost(), ((AbstractClientApplicationBase) msalRequest.application()).azureRegion());
@@ -293,7 +293,7 @@ static String discoverRegion(MsalRequest msalRequest, ServiceBundle serviceBundl
293293

294294
//Check if the REGION_NAME environment variable has a value for the region
295295
if (System.getenv(REGION_NAME) != null) {
296-
log.info(String.format("Region found in environment variable: %s",System.getenv(REGION_NAME)));
296+
log.info("Region found in environment variable: {}", System.getenv(REGION_NAME));
297297
currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_ENV_VARIABLE.telemetryValue);
298298

299299
return System.getenv(REGION_NAME);
@@ -311,19 +311,19 @@ static String discoverRegion(MsalRequest msalRequest, ServiceBundle serviceBundl
311311
IHttpResponse httpResponse = future.get(IMDS_TIMEOUT, IMDS_TIMEOUT_UNIT);
312312
//If call to IMDS endpoint was successful, return region from response body
313313
if (httpResponse.statusCode() == HttpStatus.HTTP_OK && !httpResponse.body().isEmpty()) {
314-
log.info(String.format("Region retrieved from IMDS endpoint: %s", httpResponse.body()));
314+
log.info("Region retrieved from IMDS endpoint: {}", httpResponse.body());
315315
currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_IMDS.telemetryValue);
316316

317317
return httpResponse.body();
318318
}
319-
log.warn(String.format("Call to local IMDS failed with status code: %s, or response was empty", httpResponse.statusCode()));
319+
log.warn("Call to local IMDS failed with status code: {}, or response was empty", httpResponse.statusCode());
320320
currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_FAILED_AUTODETECT.telemetryValue);
321321
} catch (Exception ex) {
322322
// handle other exceptions
323323
//IMDS call failed, cannot find region
324324
//The IMDS endpoint is only available from within an Azure environment, so the most common cause of this
325325
// exception will likely be java.net.SocketException: Network is unreachable: connect
326-
log.warn(String.format("Exception during call to local IMDS endpoint: %s", ex.getMessage()));
326+
log.warn("Exception during call to local IMDS endpoint: {}", ex.getMessage());
327327
currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_FAILED_AUTODETECT.telemetryValue);
328328
future.cancel(true);
329329

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityClient.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33

44
package com.microsoft.aad.msal4j;
55

6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
8-
96
/**
107
* Class to initialize a managed identity and identify the service.
118
*/
129
class ManagedIdentityClient {
13-
private static final Logger LOG = LoggerFactory.getLogger(ManagedIdentityClient.class);
1410

1511
static ManagedIdentitySourceType getManagedIdentitySource() {
1612
IEnvironmentVariables environmentVariables = AbstractManagedIdentitySource.getEnvironmentVariables();

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityResponse.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
import com.azure.json.JsonSerializable;
88
import com.azure.json.JsonToken;
99
import com.azure.json.JsonWriter;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
1210

1311
import java.io.IOException;
1412

1513
class ManagedIdentityResponse implements JsonSerializable<ManagedIdentityResponse> {
1614

17-
private static final Logger LOG = LoggerFactory.getLogger(ManagedIdentityResponse.class);
18-
1915
String tokenType;
2016
String accessToken;
2117
String expiresOn;

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MexParser.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class MexParser {
2525

26-
private final static Logger log = LoggerFactory.getLogger(MexParser.class);
26+
private static final Logger LOG = LoggerFactory.getLogger(MexParser.class);
2727

2828
private static final String TRANSPORT_BINDING_XPATH = "wsp:ExactlyOne/wsp:All/sp:TransportBinding";
2929
private static final String TRANSPORT_BINDING_2005_XPATH = "wsp:ExactlyOne/wsp:All/sp2005:TransportBinding";
@@ -84,15 +84,15 @@ static BindingPolicy getPolicy(String mexResponse, PolicySelector policySelector
8484
Map<String, BindingPolicy> policies = policySelector.selectPolicies(xmlDocument, xPath, logPii);
8585

8686
if (policies.isEmpty()) {
87-
log.debug("No matching policies");
87+
LOG.debug("No matching policies");
8888

8989
return null;
9090
} else {
9191
Map<String, BindingPolicy> bindings = getMatchingBindings(
9292
xmlDocument, xPath, policies, logPii);
9393

9494
if (bindings.isEmpty()) {
95-
log.debug("No matching bindings");
95+
LOG.debug("No matching bindings");
9696

9797
return null;
9898
} else {
@@ -132,7 +132,7 @@ private static BindingPolicy selectSingleMatchingPolicy(
132132
}
133133

134134
if (wstrust13 == null && wstrust2005 == null) {
135-
log.warn("No policies found with the url");
135+
LOG.warn("No policies found with the url");
136136

137137
return null;
138138
}
@@ -148,7 +148,7 @@ private static void getPortsForPolicyBindings(Document xmlDocument,
148148
xmlDocument, XPathConstants.NODESET);
149149

150150
if (portNodes.getLength() == 0) {
151-
log.warn("No ports found");
151+
LOG.warn("No ports found");
152152
} else {
153153
for (int i = 0; i < portNodes.getLength(); i++) {
154154
Node portNode = portNodes.item(i);
@@ -175,9 +175,9 @@ private static void getPortsForPolicyBindings(Document xmlDocument,
175175
bindingPolicy.setUrl(address.trim());
176176
} else {
177177
if (logPii) {
178-
log.warn("Skipping insecure endpoint" + ": " + address);
178+
LOG.warn("Skipping insecure endpoint: {}", address);
179179
} else {
180-
log.warn("Skipping insecure endpoint");
180+
LOG.warn("Skipping insecure endpoint");
181181
}
182182
}
183183
} else {
@@ -242,17 +242,17 @@ private static WSTrustVersion checkSoapActionAndTransport(XPath xPath,
242242

243243
if (soapAction.equalsIgnoreCase(RST_SOAP_ACTION)) {
244244
if (logPii) {
245-
log.debug("Found binding matching Action and Transport: " + bindingName);
245+
LOG.debug("Found binding matching Action and Transport: {}", bindingName);
246246
} else {
247-
log.debug("Found binding matching Action and Transport");
247+
LOG.debug("Found binding matching Action and Transport");
248248
}
249249

250250
return WSTrustVersion.WSTRUST13;
251251
} else if (soapAction.equalsIgnoreCase(RST_SOAP_ACTION_2005)) {
252252
if (logPii) {
253-
log.debug("Binding node did not match soap Action or Transport: " + bindingName);
253+
LOG.debug("Binding node did not match soap Action or Transport: {}", bindingName);
254254
} else {
255-
log.debug("Binding node did not match soap Action or Transport");
255+
LOG.debug("Binding node did not match soap Action or Transport");
256256
}
257257

258258
return WSTrustVersion.WSTRUST2005;
@@ -322,9 +322,9 @@ private static String checkPolicy(XPath xPath, Node node, boolean logPii)
322322
policyId = id.getNodeValue();
323323

324324
if (logPii) {
325-
log.debug("found matching policy id: " + policyId);
325+
LOG.debug("found matching policy id: {}", policyId);
326326
} else {
327-
log.debug("found matching policy");
327+
LOG.debug("found matching policy");
328328
}
329329
} else {
330330
String nodeValue = "none";
@@ -333,9 +333,9 @@ private static String checkPolicy(XPath xPath, Node node, boolean logPii)
333333
}
334334

335335
if (logPii) {
336-
log.debug("potential policy did not match required transport binding: " + nodeValue);
336+
LOG.debug("potential policy did not match required transport binding: {}", nodeValue);
337337
} else {
338-
log.debug("potential policy did not match required transport binding");
338+
LOG.debug("potential policy did not match required transport binding");
339339
}
340340
}
341341
return policyId;

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServerSideTelemetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private synchronized String buildCurrentRequestHeader() {
7777
SCHEMA_PIPE_DELIMITER;
7878

7979
if (currentRequestHeader.getBytes(StandardCharsets.UTF_8).length > CURRENT_REQUEST_MAX_SIZE) {
80-
log.warn("Current request telemetry header greater than 100 bytes");
80+
log.warn("Current request telemetry header greater than {} bytes", CURRENT_REQUEST_MAX_SIZE);
8181
}
8282

8383
return currentRequestHeader;

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServiceFabricManagedIdentitySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static URI validateAndGetUri(String msiEndpoint)
107107
try
108108
{
109109
URI endpointUri = new URI(msiEndpoint);
110-
LOG.info(String.format("[Managed Identity] Environment variables validation passed for Service Fabric Managed Identity. Endpoint URI: %s", endpointUri));
110+
LOG.info("[Managed Identity] Environment variables validation passed for Service Fabric Managed Identity. Endpoint URI: {}", endpointUri);
111111
return endpointUri;
112112
}
113113
catch (URISyntaxException ex)

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.*;
1212

1313
class TokenRequestExecutor {
14-
Logger log = LoggerFactory.getLogger(TokenRequestExecutor.class);
14+
private static final Logger LOG = LoggerFactory.getLogger(TokenRequestExecutor.class);
1515

1616
final Authority requestAuthority;
1717
final String tenant;
@@ -29,7 +29,7 @@ class TokenRequestExecutor {
2929

3030
AuthenticationResult executeTokenRequest() throws IOException {
3131

32-
log.debug("Sending token request to: {}", requestAuthority.canonicalAuthorityUrl());
32+
LOG.debug("Sending token request to: {}", requestAuthority.canonicalAuthorityUrl());
3333
OAuthHttpRequest oAuthHttpRequest = createOauthHttpRequest();
3434
HttpResponse oauthHttpResponse = oAuthHttpRequest.send();
3535
return createAuthenticationResultFromOauthHttpResponse(oauthHttpResponse);
@@ -66,7 +66,7 @@ OAuthHttpRequest createOauthHttpRequest() throws MalformedURLException {
6666
if(msalRequest.requestContext().apiParameters().extraQueryParameters() != null ){
6767
for(String key: msalRequest.requestContext().apiParameters().extraQueryParameters().keySet()){
6868
if(params.containsKey(key)){
69-
log.warn("A query parameter {} has been provided with values multiple times.", key);
69+
LOG.warn("A query parameter {} has been provided with values multiple times.", key);
7070
}
7171
params.put(key, msalRequest.requestContext().apiParameters().extraQueryParameters().get(key));
7272
}
@@ -171,7 +171,7 @@ private AuthenticationResult createAuthenticationResultFromOauthHttpResponse(Htt
171171
}
172172

173173
Logger getLog() {
174-
return this.log;
174+
return LOG;
175175
}
176176

177177
Authority getRequestAuthority() {

0 commit comments

Comments
 (0)