Skip to content

Commit

Permalink
SNOW-1652680: Limit logging on std out and info level
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Dec 4, 2024
1 parent 852b2d9 commit f62a978
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ public class SFClientConfigParser {
*/
public static SFClientConfig loadSFClientConfig(String configFilePath) throws IOException {
if (configFilePath != null) {
logger.info("Attempting to enable easy logging with file path {}", configFilePath);
logger.debug("Attempting to enable easy logging with file path {}", configFilePath);
}
String derivedConfigFilePath = null;
if (configFilePath != null && !configFilePath.isEmpty()) {
// 1. Try to read the file at configFilePath.
logger.info("Using config file specified from connection string: {}", configFilePath);
logger.debug("Using config file specified from connection string: {}", configFilePath);
derivedConfigFilePath = configFilePath;
} else if (System.getenv().containsKey(SF_CLIENT_CONFIG_ENV_NAME)) {
// 2. If SF_CLIENT_CONFIG_ENV_NAME is set, read from env.
String filePath = systemGetEnv(SF_CLIENT_CONFIG_ENV_NAME);
logger.info("Using config file specified from environment variable: {}", filePath);
logger.debug("Using config file specified from environment variable: {}", filePath);
derivedConfigFilePath = filePath;
} else {
// 3. Read SF_CLIENT_CONFIG_FILE_NAME from where jdbc jar is loaded.
String driverLocation =
Paths.get(getConfigFilePathFromJDBCJarLocation(), SF_CLIENT_CONFIG_FILE_NAME).toString();
if (Files.exists(Paths.get(driverLocation))) {
logger.info("Using config file specified from driver directory: {}", driverLocation);
logger.debug("Using config file specified from driver directory: {}", driverLocation);
derivedConfigFilePath = driverLocation;
} else {
// 4. Read SF_CLIENT_CONFIG_FILE_NAME if it is present in user home directory.
String userHomeFilePath =
Paths.get(systemGetProperty("user.home"), SF_CLIENT_CONFIG_FILE_NAME).toString();
if (Files.exists(Paths.get(userHomeFilePath))) {
logger.info("Using config file specified from home directory: {}", userHomeFilePath);
logger.debug("Using config file specified from home directory: {}", userHomeFilePath);
derivedConfigFilePath = userHomeFilePath;
}
}
Expand All @@ -73,7 +73,7 @@ public static SFClientConfig loadSFClientConfig(String configFilePath) throws IO
File configFile = new File(derivedConfigFilePath);
ObjectMapper objectMapper = new ObjectMapper();
SFClientConfig clientConfig = objectMapper.readValue(configFile, SFClientConfig.class);
logger.info(
logger.debug(
"Reading values logLevel {} and logPath {} from client configuration",
clientConfig.getCommonProps().getLogLevel(),
clientConfig.getCommonProps().getLogPath());
Expand Down
34 changes: 13 additions & 21 deletions src/main/java/net/snowflake/client/core/CredentialManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ private void initSecureStorageManager() {
logger.error("Unsupported Operating System. Expected: OSX, Windows, Linux", false);
}
} catch (NoClassDefFoundError error) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
}
}

Expand Down Expand Up @@ -97,9 +95,7 @@ void fillCachedMfaToken(SFLoginInput loginInput) throws SFException {
synchronized void fillCachedCredential(SFLoginInput loginInput, String credType)
throws SFException {
if (secureStorageManager == null) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
return;
}

Expand All @@ -109,9 +105,7 @@ synchronized void fillCachedCredential(SFLoginInput loginInput, String credType)
secureStorageManager.getCredential(
loginInput.getHostFromServerUrl(), loginInput.getUserName(), credType);
} catch (NoClassDefFoundError error) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
return;
}

Expand Down Expand Up @@ -183,19 +177,15 @@ synchronized void writeTemporaryCredential(SFLoginInput loginInput, String cred,
}

if (secureStorageManager == null) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
return;
}

try {
secureStorageManager.setCredential(
loginInput.getHostFromServerUrl(), loginInput.getUserName(), credType, cred);
} catch (NoClassDefFoundError error) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
}
}

Expand All @@ -222,18 +212,20 @@ void deleteMfaTokenCache(String host, String user) {
*/
synchronized void deleteTemporaryCredential(String host, String user, String credType) {
if (secureStorageManager == null) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
return;
}

try {
secureStorageManager.deleteCredential(host, user, credType);
} catch (NoClassDefFoundError error) {
logger.info(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
logMissingJnaJarForSecureLocalStorage();
}
}

private static void logMissingJnaJarForSecureLocalStorage() {
logger.warn(
"JNA jar files are needed for Secure Local Storage service. Please follow the Snowflake JDBC instruction for Secure Local Storage feature. Fall back to normal process.",
false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ FileCacheManager build() {
this.cacheLockFile =
new File(this.cacheFile.getParentFile(), this.baseCacheFileName + ".lck");
} catch (IOException | SecurityException ex) {
logger.info("Failed to touch the cache file. Ignored. {}", cacheFileTmp.getAbsoluteFile());
logger.debug("Failed to touch the cache file. Ignored. {}", cacheFileTmp.getAbsoluteFile());
}
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/core/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FileUtil {
Arrays.asList(PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ);

public static void logFileUsage(Path filePath, String context, boolean logReadAccess) {
logger.info("{}Accessing file: {}", getContextStr(context), filePath);
logger.debug("{}Accessing file: {}", getContextStr(context), filePath);
logWarnWhenAccessibleByOthers(filePath, context, logReadAccess);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/core/IncidentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static void writeVmMetrics(JsonGenerator json, VirtualMachineMetrics vm)
// This function can throw an error with java 11.
json.writeNumberField("fd_usage", vm.fileDescriptorUsage());
} catch (Exception e) {
logger.info("Error writing fd_usage", e);
logger.debug("Error writing fd_usage", e);
}

json.writeFieldName("thread-states");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/snowflake/client/core/SFBaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public HttpClientSettingsKey getHttpClientKey() throws SnowflakeSQLException {

private void logHttpClientInitInfo(HttpClientSettingsKey key) {
if (key.usesProxy()) {
logger.info(
logger.debug(
"Driver OCSP mode: {}, gzip disabled: {}, proxy protocol: {},"
+ " proxy host: {}, proxy port: {}, non proxy hosts: {}, proxy user: {}, proxy password is {}",
key.getOcspMode(),
Expand All @@ -687,7 +687,7 @@ private void logHttpClientInitInfo(HttpClientSettingsKey key) {
key.getProxyUser(),
key.getProxyPassword().isEmpty() ? "not set" : "set");
} else {
logger.info(
logger.debug(
"Driver OCSP mode: {}, gzip disabled: {} and no proxy",
key.getOcspMode(),
key.getGzipDisabled());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
// start heartbeat for this session so that the master token will not expire
startHeartbeatForThisSession();
stopwatch.stop();
logger.info("Session {} opened in {} ms.", getSessionId(), stopwatch.elapsedMillis());
logger.debug("Session {} opened in {} ms.", getSessionId(), stopwatch.elapsedMillis());
}

/**
Expand Down Expand Up @@ -937,7 +937,7 @@ public void close() throws SFException, SnowflakeSQLException {
}

stopwatch.stop();
logger.info(
logger.debug(
"Session {} has been successfully closed in {} ms",
getSessionId(),
stopwatch.elapsedMillis());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/snowflake/client/core/SFStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,11 @@ public Object executeHelper(
}
if (numBinds > 0 && session.getPreparedStatementLogging()) {
if (numBinds > MAX_BINDING_PARAMS_FOR_LOGGING) {
logger.info(
logger.debug(
"Number of binds exceeds logging limit. Printing off {} binding parameters.",
MAX_BINDING_PARAMS_FOR_LOGGING);
} else {
logger.info("Printing off {} binding parameters.", numBinds);
logger.debug("Printing off {} binding parameters.", numBinds);
}
int counter = 0;
// if it's an array bind, print off the first few rows from each column.
Expand All @@ -458,7 +458,7 @@ public Object executeHelper(
rows += bindRows.get(i) + ", ";
}
rows += "]";
logger.info("Column {}: {}", entry.getKey(), rows);
logger.debug("Column {}: {}", entry.getKey(), rows);
counter += numRowsPrinted;
if (counter >= MAX_BINDING_PARAMS_FOR_LOGGING) {
break;
Expand All @@ -472,7 +472,7 @@ public Object executeHelper(
break;
}
counter++;
logger.info("Column {}: {}", entry.getKey(), entry.getValue().getValue());
logger.debug("Column {}: {}", entry.getKey(), entry.getValue().getValue());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ private SecureStorageAppleManager() {
}

public static SecureStorageAppleManager builder() {
logger.info("Using Apple Keychain as a token cache storage");
logger.debug("Using Apple Keychain as a token cache storage");
return new SecureStorageAppleManager();
}

public SecureStorageStatus setCredential(String host, String user, String type, String cred) {
if (Strings.isNullOrEmpty(cred)) {
logger.info("No credential provided", false);
logger.debug("No credential provided", false);
return SecureStorageStatus.SUCCESS;
}

Expand All @@ -53,7 +53,7 @@ public SecureStorageStatus setCredential(String host, String user, String type,
}

if (errCode != SecurityLib.ERR_SEC_SUCCESS && errCode != SecurityLib.ERR_SEC_ITEM_NOT_FOUND) {
logger.info(
logger.warn(
String.format(
"Failed to check the existence of the item in keychain. Error code = %d",
Native.getLastError()));
Expand Down Expand Up @@ -81,7 +81,7 @@ public SecureStorageStatus setCredential(String host, String user, String type,
}

if (errCode != SecurityLib.ERR_SEC_SUCCESS) {
logger.info(
logger.warn(
String.format(
"Failed to set/modify the item in keychain. Error code = %d", Native.getLastError()));
return SecureStorageStatus.FAILURE;
Expand Down Expand Up @@ -115,14 +115,14 @@ public String getCredential(String host, String user, String type) {
}

if (errCode != SecurityLib.ERR_SEC_SUCCESS) {
logger.info(
logger.warn(
String.format(
"Failed to find the item in keychain or item not exists. Error code = %d",
Native.getLastError()));
return null;
}
if (dataLength[0] == 0 || data[0] == null) {
logger.info("Found empty item or no item is found", false);
logger.debug("Found empty item or no item is found", false);
return null;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public SecureStorageStatus deleteCredential(String host, String user, String typ
}

if (errCode != SecurityLib.ERR_SEC_SUCCESS && errCode != SecurityLib.ERR_SEC_ITEM_NOT_FOUND) {
logger.info(
logger.warn(
String.format(
"Failed to delete the item in keychain. Error code = %d", Native.getLastError()));
return SecureStorageStatus.FAILURE;
Expand All @@ -174,7 +174,7 @@ public SecureStorageStatus deleteCredential(String host, String user, String typ
}

if (errCode != SecurityLib.ERR_SEC_SUCCESS) {
logger.info(
logger.warn(
String.format(
"Failed to delete the item in keychain. Error code = %d", Native.getLastError()));
return SecureStorageStatus.FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private SecureStorageLinuxManager() {
.setCacheExpirationInSeconds(CACHE_EXPIRATION_IN_SECONDS)
.setCacheFileLockExpirationInSeconds(CACHE_FILE_LOCK_EXPIRATION_IN_SECONDS)
.build();
logger.info(
logger.debug(
"Using temporary file: {} as a token cache storage", fileCacheManager.getCacheFilePath());
}

Expand Down Expand Up @@ -70,7 +70,7 @@ private ObjectNode localCacheToJson() {
public synchronized SecureStorageStatus setCredential(
String host, String user, String type, String token) {
if (Strings.isNullOrEmpty(token)) {
logger.info("No token provided", false);
logger.debug("No token provided", false);
return SecureStorageStatus.SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ private SecureStorageWindowsManager() {
}

public static SecureStorageWindowsManager builder() {
logger.info("Using Windows Credential Manager as a token cache storage");
logger.debug("Using Windows Credential Manager as a token cache storage");
return new SecureStorageWindowsManager();
}

public SecureStorageStatus setCredential(String host, String user, String type, String token) {
if (Strings.isNullOrEmpty(token)) {
logger.info("No token provided", false);
logger.debug("No token provided", false);
return SecureStorageStatus.SUCCESS;
}

Expand All @@ -63,13 +63,13 @@ public SecureStorageStatus setCredential(String host, String user, String type,
}

if (!ret) {
logger.info(
logger.warn(
String.format(
"Failed to write to Windows Credential Manager. Error code = %d",
Native.getLastError()));
return SecureStorageStatus.FAILURE;
}
logger.info("Wrote to Windows Credential Manager successfully", false);
logger.debug("Wrote to Windows Credential Manager successfully", false);

return SecureStorageStatus.SUCCESS;
}
Expand All @@ -90,7 +90,7 @@ public String getCredential(String host, String user, String type) {
}

if (!ret) {
logger.info(
logger.warn(
String.format(
"Failed to read target or could not find it in Windows Credential Manager. Error code = %d",
Native.getLastError()));
Expand All @@ -104,12 +104,12 @@ public String getCredential(String host, String user, String type) {

if (SecureStorageWindowsCredentialType.typeOf(cred.Type)
!= SecureStorageWindowsCredentialType.CRED_TYPE_GENERIC) {
logger.info("Wrong type of credential. Expected: CRED_TYPE_GENERIC", false);
logger.warn("Wrong type of credential. Expected: CRED_TYPE_GENERIC", false);
return null;
}

if (cred.CredentialBlobSize == 0) {
logger.info("Returned credential is empty", false);
logger.debug("Returned credential is empty", false);
return null;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public SecureStorageStatus deleteCredential(String host, String user, String typ
}

if (!ret) {
logger.info(
logger.warn(
String.format(
"Failed to delete target in Windows Credential Manager. Error code = %d",
Native.getLastError()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/core/SystemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static int convertSystemPropertyToIntValue(String systemProperty, int defaultVal
try {
returnVal = Integer.parseInt(systemPropertyValue);
} catch (NumberFormatException ex) {
logger.info(
logger.warn(
"Failed to parse the system parameter {} with value {}",
systemProperty,
systemPropertyValue);
Expand Down
Loading

0 comments on commit f62a978

Please sign in to comment.