Skip to content

Commit

Permalink
SNOW-1652680: Limit logging on std out and info level (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Dec 6, 2024
1 parent 852b2d9 commit 6da3ca3
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/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
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/core/SFBaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.warn("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.warn("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.warn("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
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ && systemGetProperty("java.util.logging.config.file") == null) {

if (logLevel != null && logPattern != null) {
try {
logger.info("Setting logger with log level {} and log pattern {}", logLevel, logPattern);
logger.debug("Setting logger with log level {} and log pattern {}", logLevel, logPattern);
JDK14Logger.instantiateLogger(logLevel, logPattern);
} catch (IOException ex) {
throw new SnowflakeSQLLoggedException(
Expand Down Expand Up @@ -325,7 +325,7 @@ private void initSessionProperties(SnowflakeConnectString conStr, String appID,
properties.replace(property.getKey(), "900");
}
} catch (NumberFormatException ex) {
logger.info(
logger.warn(
"Invalid data type for CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY: {}",
property.getValue());
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import net.snowflake.client.core.FileUtil;
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;

/**
* An {@link OutputStream} that starts buffering to a byte array, but switches to file buffering
Expand All @@ -42,6 +44,8 @@
@Beta
public final class FileBackedOutputStream extends OutputStream {

private static final SFLogger logger = SFLoggerFactory.getLogger(FileBackedOutputStream.class);

private final int fileThreshold;
private final boolean resetOnFinalize;
private final ByteSource source;
Expand Down Expand Up @@ -105,7 +109,7 @@ protected void finalize() {
try {
reset();
} catch (Throwable t) {
t.printStackTrace(System.err);
logger.error("Exception occurred on finalize", t);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class SnowflakeCallableStatementV1 extends SnowflakePreparedStatementV1
static String parseSqlEscapeSyntax(String originalSql) {
originalSql = originalSql.trim();
if (originalSql.startsWith("{") && originalSql.endsWith("}")) {
logger.info("Curly brackets {} removed before sending sql to server.", false);
logger.debug("Curly brackets {} removed before sending sql to server.", false);
return originalSql.substring(1, originalSql.length() - 1);
}
return originalSql;
Expand Down
Loading

0 comments on commit 6da3ca3

Please sign in to comment.