diff --git a/sdk/keyvault/azure-security-keyvault-jca/README.md b/sdk/keyvault/azure-security-keyvault-jca/README.md index 7652cd209e3d8..22932ff118089 100644 --- a/sdk/keyvault/azure-security-keyvault-jca/README.md +++ b/sdk/keyvault/azure-security-keyvault-jca/README.md @@ -146,6 +146,33 @@ PEM | EC | P-521 | SHA512withECDSA | PEM | EC | P-256K | | ✘ | ## Troubleshooting + +## Configure logging +This module uses JUL (`java.util.logging`), so to configure things like the logging level you can directly modify the JUL configuration. + +Here is an example of a `logging.properties` file: +```properties +# To enable this configuration file, please add this property: +# -Djava.util.logging.config.file="src/test/resources/logging.properties" +# +# The Java logging APIs (java.util.logging) default loads logging.properties from: +# 1. $JAVA_HOME/jre/lib/ (Java 8 and before) +# 2. $JAVA_HOME/conf/ (Java 9 and above) +# +# For more information about this file, please refer to: +# 1. https://docs.oracle.com/javase/8/docs/technotes/guides/logging/overview.html#a1.8 +# 2. https://docs.oracle.com/cd/E23549_01/doc.1111/e14568/handler.htm + +handlers = java.util.logging.ConsoleHandler +java.util.logging.ConsoleHandler.level = ALL +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter +java.util.logging.SimpleFormatter.format= [%1$tF %1$tT] %3 [%4$-7s] %5$s %n + +.level = INFO +com.azure.security.keyvault.jca.level = ALL +``` + + ### General Azure Key Vault JCA clients raise exceptions. For example, if you try to check a client's identity with a certificate chain that does not include a trusted certificate, a `CertificateException` will be thrown. In the following snippet, the error is handled gracefully by catching the exception and displaying additional information about the error. diff --git a/sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/implementation/utils/AccessTokenUtil.java b/sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/implementation/utils/AccessTokenUtil.java index 413e12ce7f0a0..62d2dd02f18cb 100644 --- a/sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/implementation/utils/AccessTokenUtil.java +++ b/sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/implementation/utils/AccessTokenUtil.java @@ -87,7 +87,7 @@ public static String getAccessToken(String resource, String identity) { public static String getAccessToken(String resource, String aadAuthenticationUrl, String tenantId, String clientId, String clientSecret) { - LOGGER.entering("AuthClient", "getAccessToken", new Object[]{ + LOGGER.entering("AccessTokenUtil", "getAccessToken", new Object[]{ resource, tenantId, clientId, clientSecret}); LOGGER.info("Getting access token using client ID / client secret"); String result = null; @@ -121,7 +121,7 @@ public static String getAccessToken(String resource, String aadAuthenticationUrl * @return the authorization token. */ private static String getAccessTokenOnAppService(String resource, String clientId) { - LOGGER.entering("AuthClient", "getAccessTokenOnAppService", resource); + LOGGER.entering("AccessTokenUtil", "getAccessTokenOnAppService", resource); LOGGER.info("Getting access token using managed identity based on MSI_SECRET"); String result = null; @@ -143,7 +143,7 @@ private static String getAccessTokenOnAppService(String resource, String clientI OAuthToken token = (OAuthToken) JsonConverterUtil.fromJson(body, OAuthToken.class); result = token.getAccessToken(); } - LOGGER.exiting("AuthClient", "getAccessTokenOnAppService", result); + LOGGER.exiting("AccessTokenUtil", "getAccessTokenOnAppService", result); return result; } @@ -155,7 +155,7 @@ private static String getAccessTokenOnAppService(String resource, String clientI * @return the authorization token. */ private static String getAccessTokenOnOthers(String resource, String identity) { - LOGGER.entering("AuthClient", "getAccessTokenOnOthers", resource); + LOGGER.entering("AccessTokenUtil", "getAccessTokenOnOthers", resource); LOGGER.info("Getting access token using managed identity"); if (identity != null) { LOGGER.log(INFO, "Using managed identity with object ID: {0}", identity); @@ -177,7 +177,7 @@ private static String getAccessTokenOnOthers(String resource, String identity) { OAuthToken token = (OAuthToken) JsonConverterUtil.fromJson(body, OAuthToken.class); result = token.getAccessToken(); } - LOGGER.exiting("AuthClient", "getAccessTokenOnOthers", result); + LOGGER.exiting("AccessTokenUtil", "getAccessTokenOnOthers", result); return result; } } diff --git a/sdk/keyvault/azure-security-keyvault-jca/src/test/resources/logging.properties b/sdk/keyvault/azure-security-keyvault-jca/src/test/resources/logging.properties new file mode 100644 index 0000000000000..33afbfd0232b1 --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-jca/src/test/resources/logging.properties @@ -0,0 +1,18 @@ +# To enable this configuration file, please add this property: +# -Djava.util.logging.config.file="src/test/resources/logging.properties" +# +# The Java logging APIs (java.util.logging) default loads logging.properties from: +# 1. $JAVA_HOME/jre/lib/ (Java 8 and before) +# 2. $JAVA_HOME/conf/ (Java 9 and above) +# +# For more information about this file, please refer to: +# 1. https://docs.oracle.com/javase/8/docs/technotes/guides/logging/overview.html#a1.8 +# 2. https://docs.oracle.com/cd/E23549_01/doc.1111/e14568/handler.htm + +handlers = java.util.logging.ConsoleHandler +java.util.logging.ConsoleHandler.level = ALL +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter +java.util.logging.SimpleFormatter.format= [%1$tF %1$tT] %3 [%4$-7s] %5$s %n + +.level = INFO +com.azure.security.keyvault.jca.level = ALL