Skip to content

Commit

Permalink
Add logging.properties to configure log (Azure#23516)
Browse files Browse the repository at this point in the history
Co-authored-by: vcolin7 <vicolina@microsoft.com>
  • Loading branch information
Rujun Chen and vcolin7 committed Aug 12, 2021
1 parent 04fc69a commit f4c4c67
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
27 changes: 27 additions & 0 deletions sdk/keyvault/azure-security-keyvault-jca/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f4c4c67

Please sign in to comment.