From 7e8abd2dbb3f2a225e5e43ffd4c18626875439f7 Mon Sep 17 00:00:00 2001 From: alexradzin Date: Sun, 5 May 2024 19:22:19 +0300 Subject: [PATCH] FIR-32836: log is simplified now - no lombok in log --- build.gradle | 1 + lombok.config | 1 - .../java/integration/IntegrationTest.java | 2 - .../tests/PreparedStatementArrayTest.java | 2 - .../tests/PreparedStatementTest.java | 3 - .../tests/StatementCancelTest.java | 11 +- .../java/integration/tests/StatementTest.java | 2 - .../integration/tests/SystemEngineTest.java | 17 +-- .../java/integration/tests/TimeoutTest.java | 8 +- .../java/integration/tests/TimestampTest.java | 2 - .../java/com/firebolt/FireboltDriver.java | 13 +- .../firebolt/jdbc/client/FireboltClient.java | 9 +- .../jdbc/client/HttpClientConfig.java | 14 +-- .../jdbc/client/UsageTrackerUtil.java | 13 +- .../client/account/FireboltAccountClient.java | 2 - .../FireboltAuthenticationClient.java | 11 +- .../client/config/OkHttpClientCreator.java | 2 - .../jdbc/client/config/RetryInterceptor.java | 7 +- .../socket/FireboltSSLSocketFactory.java | 10 +- .../config/socket/FireboltSocketFactory.java | 10 +- .../jdbc/client/config/socket/SocketUtil.java | 19 ++- .../client/query/StatementClientImpl.java | 11 +- .../jdbc/connection/FireboltConnection.java | 17 +-- .../com/firebolt/jdbc/connection/UrlUtil.java | 7 +- .../settings/FireboltProperties.java | 2 - .../com/firebolt/jdbc/log/FireboltLogger.java | 35 ------ .../java/com/firebolt/jdbc/log/JDKLogger.java | 111 ------------------ .../com/firebolt/jdbc/log/SLF4JLogger.java | 89 -------------- .../metadata/FireboltDatabaseMetadata.java | 2 - .../jdbc/resultset/FireboltResultSet.java | 11 +- .../jdbc/resultset/column/Column.java | 9 +- .../jdbc/resultset/column/ColumnType.java | 7 +- .../FireboltAuthenticationService.java | 13 +- .../service/FireboltEngineApiService.java | 2 - ...ireboltEngineInformationSchemaService.java | 3 - .../service/FireboltStatementService.java | 2 - .../jdbc/statement/FireboltStatement.java | 26 ++-- .../statement/StatementResultWrapper.java | 14 +-- .../jdbc/statement/StatementUtil.java | 9 +- .../FireboltPreparedStatement.java | 10 +- .../rawstatement/RawStatementWrapper.java | 2 - .../java/com/firebolt/jdbc/type/BaseType.java | 1 - .../jdbc/type/array/SqlArrayUtil.java | 9 +- .../firebolt/jdbc/type/date/SqlDateUtil.java | 1 - .../com/firebolt/jdbc/util/CloseableUtil.java | 6 +- .../firebolt/jdbc/util/InputStreamUtil.java | 7 +- .../com/firebolt/jdbc/util/LoggerUtil.java | 51 ++++---- .../com/firebolt/jdbc/util/PropertyUtil.java | 1 - .../com/firebolt/jdbc/util/VersionUtil.java | 9 +- .../java/com/firebolt/FireboltDriverTest.java | 6 +- .../com/firebolt/jdbc/log/JDKLoggerTest.java | 68 ----------- .../firebolt/jdbc/log/LogLevelExample.java | 0 .../firebolt/jdbc/log/SLF4JLoggerTest.java | 68 ----------- .../firebolt/jdbc/util/LoggerUtilTest.java | 16 +-- 54 files changed, 198 insertions(+), 586 deletions(-) delete mode 100644 src/main/java/com/firebolt/jdbc/log/FireboltLogger.java delete mode 100644 src/main/java/com/firebolt/jdbc/log/JDKLogger.java delete mode 100644 src/main/java/com/firebolt/jdbc/log/SLF4JLogger.java delete mode 100644 src/test/java/com/firebolt/jdbc/log/JDKLoggerTest.java delete mode 100644 src/test/java/com/firebolt/jdbc/log/LogLevelExample.java delete mode 100644 src/test/java/com/firebolt/jdbc/log/SLF4JLoggerTest.java diff --git a/build.gradle b/build.gradle index be1e56db8..066ca2b14 100644 --- a/build.gradle +++ b/build.gradle @@ -69,6 +69,7 @@ dependencies { implementation 'net.jodah:expiringmap:0.5.11' implementation 'org.apache.commons:commons-text:1.12.0' implementation 'org.lz4:lz4-java:1.8.0' + implementation 'org.slf4j:jul-to-slf4j:2.0.13' implementation fileTree(dir: 'libs', includes: ['*.jar']) diff --git a/lombok.config b/lombok.config index 86058d25d..9ab6f2abe 100644 --- a/lombok.config +++ b/lombok.config @@ -1,4 +1,3 @@ lombok.anyConstructor.addConstructorProperties = true config.stopBubbling = true lombok.addLombokGeneratedAnnotation = true -lombok.log.custom.declaration = com.firebolt.jdbc.log.FireboltLogger com.firebolt.jdbc.util.LoggerUtil.getLogger(NAME) \ No newline at end of file diff --git a/src/integrationTest/java/integration/IntegrationTest.java b/src/integrationTest/java/integration/IntegrationTest.java index d51246930..06549081c 100644 --- a/src/integrationTest/java/integration/IntegrationTest.java +++ b/src/integrationTest/java/integration/IntegrationTest.java @@ -1,7 +1,6 @@ package integration; import com.firebolt.jdbc.client.HttpClientConfig; -import lombok.CustomLog; import lombok.SneakyThrows; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.TestInstance; @@ -17,7 +16,6 @@ import static com.firebolt.jdbc.connection.FireboltConnectionUserPassword.SYSTEM_ENGINE_NAME; import static org.junit.jupiter.api.Assertions.assertNotNull; -@CustomLog @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Tag("common") public abstract class IntegrationTest { diff --git a/src/integrationTest/java/integration/tests/PreparedStatementArrayTest.java b/src/integrationTest/java/integration/tests/PreparedStatementArrayTest.java index c0d08f173..7a39e693c 100644 --- a/src/integrationTest/java/integration/tests/PreparedStatementArrayTest.java +++ b/src/integrationTest/java/integration/tests/PreparedStatementArrayTest.java @@ -3,7 +3,6 @@ import com.firebolt.jdbc.type.FireboltDataType; import com.firebolt.jdbc.type.array.FireboltArray; import integration.IntegrationTest; -import lombok.CustomLog; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -@CustomLog class PreparedStatementArrayTest extends IntegrationTest { enum PreparedStatementValueSetter { ARRAY { diff --git a/src/integrationTest/java/integration/tests/PreparedStatementTest.java b/src/integrationTest/java/integration/tests/PreparedStatementTest.java index 89f0e54c2..306335dc8 100644 --- a/src/integrationTest/java/integration/tests/PreparedStatementTest.java +++ b/src/integrationTest/java/integration/tests/PreparedStatementTest.java @@ -9,7 +9,6 @@ import integration.ConnectionInfo; import integration.IntegrationTest; import lombok.Builder; -import lombok.CustomLog; import lombok.EqualsAndHashCode; import lombok.Value; import org.junit.jupiter.api.AfterEach; @@ -33,7 +32,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; @@ -51,7 +49,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -@CustomLog class PreparedStatementTest extends IntegrationTest { @BeforeEach diff --git a/src/integrationTest/java/integration/tests/StatementCancelTest.java b/src/integrationTest/java/integration/tests/StatementCancelTest.java index a2538307b..83a01c732 100644 --- a/src/integrationTest/java/integration/tests/StatementCancelTest.java +++ b/src/integrationTest/java/integration/tests/StatementCancelTest.java @@ -5,7 +5,6 @@ import com.firebolt.jdbc.statement.FireboltStatement; import integration.EnvironmentCondition; import integration.IntegrationTest; -import lombok.CustomLog; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -17,13 +16,15 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; import static integration.EnvironmentCondition.Attribute.databaseVersion; import static integration.EnvironmentCondition.Comparison.GE; import static org.junit.jupiter.api.Assertions.assertEquals; -@CustomLog class StatementCancelTest extends IntegrationTest { + private static final Logger log = Logger.getLogger(StatementCancelTest.class.getName()); @BeforeEach void beforeEach() { @@ -91,11 +92,11 @@ private void verifyThatNoMoreRecordsAreAdded(Connection connection, String table // data is available. long waitForResultTime = insertTime / 2; long waitForResultDelay = waitForResultTime / 10; - log.info("verifyThatNoMoreRecordsAreAdded insertTime={}, waitForResultTime={}", insertTime, waitForResultTime); + log.log(Level.INFO, "verifyThatNoMoreRecordsAreAdded insertTime={0}, waitForResultTime={0}", new Object[] {insertTime, waitForResultTime}); int count0; int i = 0; for (count0 = count(connection, tableName); i < 10; count0 = count(connection, tableName), i++) { - log.info("verifyThatNoMoreRecordsAreAdded count0={}", count0); + log.log(Level.INFO, "verifyThatNoMoreRecordsAreAdded count0={0}", count0); if (count0 > 0) { break; } @@ -108,7 +109,7 @@ private void verifyThatNoMoreRecordsAreAdded(Connection connection, String table int count1 = count(connection, tableName); Thread.sleep(insertTime); // waiting to see if more records are being added int count2 = count(connection, tableName); - log.info("verifyThatNoMoreRecordsAreAdded count1={}, count2={}", count1, count2); + log.log(Level.INFO, "verifyThatNoMoreRecordsAreAdded count1={0}, count2={1}", new Object[] {count1, count2}); assertEquals(count1, count2); } diff --git a/src/integrationTest/java/integration/tests/StatementTest.java b/src/integrationTest/java/integration/tests/StatementTest.java index f8a0579c6..05331d865 100644 --- a/src/integrationTest/java/integration/tests/StatementTest.java +++ b/src/integrationTest/java/integration/tests/StatementTest.java @@ -5,7 +5,6 @@ import integration.ConnectionInfo; import integration.IntegrationTest; import kotlin.collections.ArrayDeque; -import lombok.CustomLog; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -42,7 +41,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -@CustomLog class StatementTest extends IntegrationTest { @BeforeEach diff --git a/src/integrationTest/java/integration/tests/SystemEngineTest.java b/src/integrationTest/java/integration/tests/SystemEngineTest.java index 00e9cd573..29bbc30ff 100644 --- a/src/integrationTest/java/integration/tests/SystemEngineTest.java +++ b/src/integrationTest/java/integration/tests/SystemEngineTest.java @@ -6,7 +6,6 @@ import integration.ConnectionInfo; import integration.EnvironmentCondition; import integration.IntegrationTest; -import lombok.CustomLog; import org.junit.Assert; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -33,6 +32,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Stream; import static java.lang.String.format; @@ -45,7 +46,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -@CustomLog @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class SystemEngineTest extends IntegrationTest { @@ -59,12 +59,14 @@ public class SystemEngineTest extends IntegrationTest { private static final String TABLE1 = TABLE + "_1"; private static final String TABLE2 = TABLE + "_2"; + private static final Logger log = Logger.getLogger(SystemEngineTest.class.getName()); + @BeforeAll void beforeAll() { try { executeStatementFromFile("/statements/system/ddl.sql", getSystemEngineName()); } catch (Exception e) { - log.warn("Could not execute statement", e); + log.log(Level.WARNING, "Could not execute statement", e); } } @@ -73,7 +75,7 @@ void afterAll() { try { executeStatementFromFile("/statements/system/cleanup.sql", getSystemEngineName()); } catch (Exception e) { - log.warn("Could not execute statement", e); + log.log(Level.WARNING, "Could not execute statement", e); } } @@ -153,7 +155,7 @@ void useDatabase(String entityType) throws SQLException { try (Statement statement = connection.createStatement()) { statement.executeUpdate(query); } catch (SQLException e) { // catch just in case to do our best to clean everything even if test has failed - log.warn("Cannot perform query {}", query, e); + log.log(Level.WARNING, "Cannot perform query " + query, e); } } } @@ -273,9 +275,8 @@ void shouldExecuteEngineManagementQueries() throws SQLException { format("DROP DATABASE %s", SECOND_DATABASE_NAME)}) { try (Statement statement = connection.createStatement()) { statement.executeUpdate(query); - } catch ( - SQLException e) { // catch just in case to do our best to clean everything even if test has failed - log.warn("Cannot perform query {}", query, e); + } catch (SQLException e) { // catch just in case to do our best to clean everything even if test has failed + log.log(Level.WARNING, "Cannot perform query " + query, e); } } } diff --git a/src/integrationTest/java/integration/tests/TimeoutTest.java b/src/integrationTest/java/integration/tests/TimeoutTest.java index a0e77a348..ac3e14b2e 100644 --- a/src/integrationTest/java/integration/tests/TimeoutTest.java +++ b/src/integrationTest/java/integration/tests/TimeoutTest.java @@ -2,9 +2,7 @@ import com.firebolt.jdbc.connection.FireboltConnection; import integration.EnvironmentCondition; -import integration.EnvironmentCondition.Comparison; import integration.IntegrationTest; -import lombok.CustomLog; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -16,16 +14,18 @@ import java.sql.Statement; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; import static integration.EnvironmentCondition.Attribute.databaseVersion; import static integration.EnvironmentCondition.Comparison.GE; import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertTrue; -@CustomLog class TimeoutTest extends IntegrationTest { private static final int MIN_TIME_SECONDS = 350; private static final Map SERIES_SIZE = Map.of(1, 80000000000L, 2, 180000000000L); + private static final Logger log = Logger.getLogger(TimeoutTest.class.getName()); private long startTime; @BeforeEach @@ -37,7 +37,7 @@ void before() { void after() { long endTime = System.nanoTime(); long elapsedTimeSeconds = (endTime - startTime) / 1_000_000_000; - log.info("Time elapsed: {} seconds", elapsedTimeSeconds); + log.log(Level.INFO, "Time elapsed: {0} seconds", elapsedTimeSeconds); assertTrue(elapsedTimeSeconds > MIN_TIME_SECONDS, format("Test is too short. It took %d but should take at least %d seconds", elapsedTimeSeconds, MIN_TIME_SECONDS)); } diff --git a/src/integrationTest/java/integration/tests/TimestampTest.java b/src/integrationTest/java/integration/tests/TimestampTest.java index bfc0e4487..99732ea0e 100644 --- a/src/integrationTest/java/integration/tests/TimestampTest.java +++ b/src/integrationTest/java/integration/tests/TimestampTest.java @@ -3,7 +3,6 @@ import com.firebolt.jdbc.testutils.AssertionUtil; import integration.IntegrationTest; import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; -import lombok.CustomLog; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -37,7 +36,6 @@ import static java.sql.Types.TIMESTAMP_WITH_TIMEZONE; import static org.junit.jupiter.api.Assertions.assertEquals; -@CustomLog @DefaultTimeZone("UTC") class TimestampTest extends IntegrationTest { private static final TimeZone UTC_TZ = TimeZone.getTimeZone("UTC"); diff --git a/src/main/java/com/firebolt/FireboltDriver.java b/src/main/java/com/firebolt/FireboltDriver.java index 96b759a7e..3707fe321 100644 --- a/src/main/java/com/firebolt/FireboltDriver.java +++ b/src/main/java/com/firebolt/FireboltDriver.java @@ -1,27 +1,28 @@ package com.firebolt; import com.firebolt.jdbc.connection.FireboltConnection; -import com.firebolt.jdbc.exception.FireboltSQLFeatureNotSupportedException; +import com.firebolt.jdbc.util.LoggerUtil; import com.firebolt.jdbc.util.PropertyUtil; import com.firebolt.jdbc.util.VersionUtil; -import lombok.CustomLog; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverPropertyInfo; import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; import java.util.Properties; import java.util.logging.Logger; -@CustomLog public class FireboltDriver implements Driver { public static final String JDBC_FIREBOLT = "jdbc:firebolt:"; + private static Logger root; + private static final Logger log; static { try { java.sql.DriverManager.registerDriver(new FireboltDriver()); + root = LoggerUtil.getRootLogger(); + log = Logger.getLogger(FireboltDriver.class.getName()); log.info("Firebolt Driver registered"); } catch (SQLException ex) { throw new RuntimeException("Cannot register the driver"); @@ -59,7 +60,7 @@ public boolean jdbcCompliant() { } @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new FireboltSQLFeatureNotSupportedException(); + public Logger getParentLogger() { + return root; } } diff --git a/src/main/java/com/firebolt/jdbc/client/FireboltClient.java b/src/main/java/com/firebolt/jdbc/client/FireboltClient.java index 76c1f2b92..e1b361792 100644 --- a/src/main/java/com/firebolt/jdbc/client/FireboltClient.java +++ b/src/main/java/com/firebolt/jdbc/client/FireboltClient.java @@ -4,7 +4,6 @@ import com.firebolt.jdbc.exception.FireboltException; import com.firebolt.jdbc.resultset.compress.LZ4InputStream; import com.firebolt.jdbc.util.CloseableUtil; -import lombok.CustomLog; import lombok.Getter; import lombok.NonNull; import okhttp3.Call; @@ -28,6 +27,8 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import static java.lang.String.format; @@ -36,13 +37,13 @@ import static java.util.Optional.ofNullable; @Getter -@CustomLog public abstract class FireboltClient { private static final String HEADER_AUTHORIZATION = "Authorization"; private static final String HEADER_AUTHORIZATION_BEARER_PREFIX_VALUE = "Bearer "; private static final String HEADER_USER_AGENT = "User-Agent"; private static final String HEADER_PROTOCOL_VERSION = "Firebolt-Protocol-Version"; + private static final Logger log = Logger.getLogger(FireboltClient.class.getName()); private final OkHttpClient httpClient; private final String headerUserAgentValue; protected final FireboltConnection connection; @@ -169,7 +170,7 @@ private String extractErrorMessage(Response response, boolean isCompress) throws try { entityBytes = response.body() != null ? response.body().bytes() : null; } catch (IOException e) { - log.warn("Could not parse response containing the error message from Firebolt", e); + log.log(Level.WARNING, "Could not parse response containing the error message from Firebolt", e); String errorResponseMessage = format("Server failed to execute query%ninternal error:%n%s", getInternalErrorWithHeadersText(response)); throw new FireboltException(errorResponseMessage, response.code(), e); @@ -184,7 +185,7 @@ private String extractErrorMessage(Response response, boolean isCompress) throws return new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)).lines() .collect(Collectors.joining("\n")) + "\n"; } catch (Exception e) { - log.warn("Could not decompress error from server"); + log.log(Level.WARNING, "Could not decompress error from server"); } } return new String(entityBytes, StandardCharsets.UTF_8); diff --git a/src/main/java/com/firebolt/jdbc/client/HttpClientConfig.java b/src/main/java/com/firebolt/jdbc/client/HttpClientConfig.java index 7849c65a8..557b0746f 100644 --- a/src/main/java/com/firebolt/jdbc/client/HttpClientConfig.java +++ b/src/main/java/com/firebolt/jdbc/client/HttpClientConfig.java @@ -1,20 +1,18 @@ package com.firebolt.jdbc.client; +import com.firebolt.jdbc.client.config.OkHttpClientCreator; +import com.firebolt.jdbc.connection.settings.FireboltProperties; +import okhttp3.OkHttpClient; + import java.io.IOException; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; +import java.util.logging.Logger; -import com.firebolt.jdbc.client.config.OkHttpClientCreator; -import com.firebolt.jdbc.connection.settings.FireboltProperties; - -import lombok.CustomLog; -import okhttp3.OkHttpClient; - -@CustomLog public class HttpClientConfig { - + private static final Logger log = Logger.getLogger(HttpClientConfig.class.getName()); private static OkHttpClient instance; private HttpClientConfig() { diff --git a/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java b/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java index 55aaa8eca..409c07ddd 100644 --- a/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java +++ b/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java @@ -1,16 +1,17 @@ package com.firebolt.jdbc.client; import com.firebolt.jdbc.util.VersionUtil; -import lombok.CustomLog; import lombok.experimental.UtilityClass; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; -@CustomLog @UtilityClass public class UsageTrackerUtil { + private static final Logger log = Logger.getLogger(UsageTrackerUtil.class.getName()); public static final Map CLIENT_MAP = Map.of( "Tableau", "com.tableau", "Looker", "com.looker", @@ -24,7 +25,7 @@ private static String getVersionForClass(String name) { Class c = Class.forName(name); return c.getPackage().getImplementationVersion(); } catch (ClassNotFoundException e) { - log.debug("Unable to get version for class " + name); + log.log(Level.FINE, "Unable to get version for class {0}", name); return ""; } } @@ -38,13 +39,13 @@ public Map getClients(StackTraceElement[] stack, Map connectorEntry : clientMap.entrySet()) { if (s.getClassName().contains(connectorEntry.getValue())) { String version = getVersionForClass(s.getClassName()); - log.debug("Detected running from " + connectorEntry.getKey() + " Version " + version); + log.log(Level.FINE, "Detected running from {0} Version {1}", new Object[] {connectorEntry.getKey(), version}); clients.put(connectorEntry.getKey(), version); } } } if (clients.isEmpty()) { - log.debug("No clients detected for tracking"); + log.log(Level.FINE, "No clients detected for tracking"); } return clients; } @@ -59,7 +60,7 @@ private static Map extractNameToVersion(String namesAndVersions) nameToVersion.put(connectorInfo[0], connectorInfo[1]); } } else { - log.debug(String.format("Incorrect connector format is provided: %s, Expected: ConnA:1.0.2,ConnB:2.9.3", namesAndVersions)); + log.log(Level.FINE, "Incorrect connector format is provided: {0}, Expected: ConnA:1.0.2,ConnB:2.9.3", namesAndVersions); } return nameToVersion; } diff --git a/src/main/java/com/firebolt/jdbc/client/account/FireboltAccountClient.java b/src/main/java/com/firebolt/jdbc/client/account/FireboltAccountClient.java index dd0fc331a..547c765ce 100644 --- a/src/main/java/com/firebolt/jdbc/client/account/FireboltAccountClient.java +++ b/src/main/java/com/firebolt/jdbc/client/account/FireboltAccountClient.java @@ -8,14 +8,12 @@ import com.firebolt.jdbc.connection.FireboltConnection; import com.firebolt.jdbc.exception.ExceptionType; import com.firebolt.jdbc.exception.FireboltException; -import lombok.CustomLog; import okhttp3.OkHttpClient; import java.io.IOException; import static java.lang.String.format; -@CustomLog public class FireboltAccountClient extends FireboltClient { private static final String GET_ACCOUNT_ID_URI = "%s/iam/v2/accounts:getIdByName?accountName=%s"; diff --git a/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java b/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java index 6c815d608..6461dc20e 100644 --- a/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java +++ b/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java @@ -4,15 +4,16 @@ import com.firebolt.jdbc.connection.FireboltConnection; import com.firebolt.jdbc.connection.FireboltConnectionTokens; import com.firebolt.jdbc.exception.FireboltException; -import lombok.CustomLog; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; -@CustomLog public abstract class FireboltAuthenticationClient extends FireboltClient { + private static final Logger log = Logger.getLogger(FireboltAuthenticationClient.class.getName()); protected FireboltAuthenticationClient(OkHttpClient httpClient, FireboltConnection connection, String customDrivers, String customClients) { @@ -32,7 +33,7 @@ public FireboltConnectionTokens postConnectionTokens(String host, String user, S throws IOException, FireboltException { AuthenticationRequest authenticationRequest = getAuthenticationRequest(user, password, host, environment); String uri = authenticationRequest.getUri(); - log.debug("Creating connection with url {}", uri); + log.log(Level.FINE, "Creating connection with url {0}", uri); Request request = createPostRequest(uri, null, authenticationRequest.getRequestBody(), null); try (Response response = execute(request, host)) { String responseString = getResponseAsString(response); @@ -46,13 +47,13 @@ public FireboltConnectionTokens postConnectionTokens(String host, String user, S private void logToken(FireboltConnectionTokens connectionTokens) { logIfPresent(connectionTokens.getAccessToken(), "Retrieved access_token"); if (connectionTokens.getExpiresInSeconds() >=- 0) { - log.debug("Retrieved expires_in"); + log.log(Level.FINE, "Retrieved expires_in"); } } private void logIfPresent(String token, String message) { if (token != null && !token.isEmpty()) { - log.debug(message); + log.log(Level.FINE, message); } } diff --git a/src/main/java/com/firebolt/jdbc/client/config/OkHttpClientCreator.java b/src/main/java/com/firebolt/jdbc/client/config/OkHttpClientCreator.java index da5fe01e2..e45870b9e 100644 --- a/src/main/java/com/firebolt/jdbc/client/config/OkHttpClientCreator.java +++ b/src/main/java/com/firebolt/jdbc/client/config/OkHttpClientCreator.java @@ -4,7 +4,6 @@ import com.firebolt.jdbc.client.config.socket.FireboltSocketFactory; import com.firebolt.jdbc.connection.settings.FireboltProperties; import lombok.Builder; -import lombok.CustomLog; import lombok.Value; import lombok.experimental.UtilityClass; import okhttp3.ConnectionPool; @@ -36,7 +35,6 @@ * Class to configure the http client using the session settings */ @UtilityClass -@CustomLog public class OkHttpClientCreator { private static final String SSL_STRICT_MODE = "strict"; diff --git a/src/main/java/com/firebolt/jdbc/client/config/RetryInterceptor.java b/src/main/java/com/firebolt/jdbc/client/config/RetryInterceptor.java index 9ab7c6864..8959d5681 100644 --- a/src/main/java/com/firebolt/jdbc/client/config/RetryInterceptor.java +++ b/src/main/java/com/firebolt/jdbc/client/config/RetryInterceptor.java @@ -1,6 +1,5 @@ package com.firebolt.jdbc.client.config; -import lombok.CustomLog; import lombok.NonNull; import lombok.RequiredArgsConstructor; import okhttp3.Interceptor; @@ -11,6 +10,8 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_BAD_GATEWAY; import static java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT; @@ -18,11 +19,11 @@ import static java.net.HttpURLConnection.HTTP_UNAVAILABLE; @RequiredArgsConstructor -@CustomLog public class RetryInterceptor implements Interceptor { private static final Set RETRYABLE_RESPONSE_CODES = new HashSet<>( Arrays.asList(HTTP_CLIENT_TIMEOUT, HTTP_BAD_GATEWAY, HTTP_UNAVAILABLE, HTTP_GATEWAY_TIMEOUT)); + private static final Logger log = Logger.getLogger(RetryInterceptor.class.getName()); private final int maxRetries; @@ -44,7 +45,7 @@ public Response intercept(@NonNull Chain chain) throws IOException { failureInfo = String.format("Failure #%d - Response code: %d. Retrying to send the request.", tryCount, response.code()); } - log.warn(failureInfo); + log.log(Level.WARNING, failureInfo); // retry the request response.close(); diff --git a/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSSLSocketFactory.java b/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSSLSocketFactory.java index 5a6fe7e45..c1f3b06a5 100644 --- a/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSSLSocketFactory.java +++ b/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSSLSocketFactory.java @@ -1,18 +1,14 @@ package com.firebolt.jdbc.client.config.socket; -import static com.firebolt.jdbc.client.config.socket.SocketUtil.wrap; +import com.firebolt.jdbc.connection.settings.FireboltProperties; +import javax.net.ssl.SSLSocketFactory; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; -import javax.net.ssl.SSLSocketFactory; - -import com.firebolt.jdbc.connection.settings.FireboltProperties; - -import lombok.CustomLog; +import static com.firebolt.jdbc.client.config.socket.SocketUtil.wrap; -@CustomLog public class FireboltSSLSocketFactory extends SSLSocketFactory { private final SSLSocketFactory delegate; private final FireboltProperties fireboltProperties; diff --git a/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSocketFactory.java b/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSocketFactory.java index 299715bda..e424c41b0 100644 --- a/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSocketFactory.java +++ b/src/main/java/com/firebolt/jdbc/client/config/socket/FireboltSocketFactory.java @@ -1,18 +1,14 @@ package com.firebolt.jdbc.client.config.socket; -import static com.firebolt.jdbc.client.config.socket.SocketUtil.wrap; +import com.firebolt.jdbc.connection.settings.FireboltProperties; +import javax.net.SocketFactory; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; -import javax.net.SocketFactory; - -import com.firebolt.jdbc.connection.settings.FireboltProperties; - -import lombok.CustomLog; +import static com.firebolt.jdbc.client.config.socket.SocketUtil.wrap; -@CustomLog public class FireboltSocketFactory extends SocketFactory { private static final javax.net.SocketFactory delegate = SocketFactory.getDefault(); private final FireboltProperties fireboltProperties; diff --git a/src/main/java/com/firebolt/jdbc/client/config/socket/SocketUtil.java b/src/main/java/com/firebolt/jdbc/client/config/socket/SocketUtil.java index cd70d43ab..61b080b25 100644 --- a/src/main/java/com/firebolt/jdbc/client/config/socket/SocketUtil.java +++ b/src/main/java/com/firebolt/jdbc/client/config/socket/SocketUtil.java @@ -1,19 +1,19 @@ package com.firebolt.jdbc.client.config.socket; -import java.io.IOException; -import java.net.Socket; -import java.net.SocketOption; - import com.firebolt.jdbc.connection.settings.FireboltProperties; - import jdk.net.ExtendedSocketOptions; import jdk.net.Sockets; -import lombok.CustomLog; import lombok.experimental.UtilityClass; +import java.io.IOException; +import java.net.Socket; +import java.net.SocketOption; +import java.util.logging.Level; +import java.util.logging.Logger; + @UtilityClass -@CustomLog public class SocketUtil { + private static final Logger log = Logger.getLogger(SocketUtil.class.getName()); public static Socket wrap(Socket s, FireboltProperties fireboltProperties) throws IOException { s.setKeepAlive(true); @@ -23,7 +23,7 @@ public static Socket wrap(Socket s, FireboltProperties fireboltProperties) throw setSocketOption(s, ExtendedSocketOptions.TCP_KEEPCOUNT, fireboltProperties.getTcpKeepCount()); setSocketOption(s, ExtendedSocketOptions.TCP_KEEPINTERVAL, fireboltProperties.getTcpKeepInterval()); } catch (Error | Exception e) { - log.debug("Could not set socket options", e); + log.log(Level.FINE, "Could not set socket options", e); } return s; } @@ -32,8 +32,7 @@ private void setSocketOption(Socket socket, SocketOption option, int va try { Sockets.setOption(socket, option, value); } catch (Exception e) { - log.debug("Could not set the socket option {}. The operation is not supported: {}", option.name(), - e.getMessage()); + log.log(Level.FINE, "Could not set the socket option {0}. The operation is not supported: {1}", new Object[] {option.name(), e.getMessage()}); } } } diff --git a/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java b/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java index 41d6528d5..8d4873345 100644 --- a/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java +++ b/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java @@ -11,7 +11,6 @@ import com.firebolt.jdbc.statement.rawstatement.RawStatement; import com.firebolt.jdbc.util.CloseableUtil; import com.firebolt.jdbc.util.PropertyUtil; -import lombok.CustomLog; import lombok.NonNull; import okhttp3.Call; import okhttp3.Dispatcher; @@ -38,6 +37,8 @@ import java.util.Optional; import java.util.function.BiPredicate; import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; import static com.firebolt.jdbc.connection.settings.FireboltQueryParameterKey.DEFAULT_FORMAT; @@ -49,7 +50,6 @@ import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; import static java.util.Optional.ofNullable; -@CustomLog public class StatementClientImpl extends FireboltClient implements StatementClient { private static final String TAB_SEPARATED_WITH_NAMES_AND_TYPES_FORMAT = "TabSeparatedWithNamesAndTypes"; @@ -57,6 +57,7 @@ public class StatementClientImpl extends FireboltClient implements StatementClie Pattern.compile("HTTP status code: 401"), "Please associate user with your service account.", Pattern.compile("Engine .+? does not exist or not authorized"), "Please grant at least one role to user associated your service account." ); + private static final Logger log = Logger.getLogger(StatementClientImpl.class.getName()); private final BiPredicate isCallWithLabel = (call, label) -> call.request().tag() instanceof String && Objects.equals(call.request().tag(), label); // visible for testing @@ -158,11 +159,11 @@ public InputStream executeSqlStatement(@NonNull StatementInfoWrapper statementIn private InputStream executeSqlStatementWithRetryOnUnauthorized(String label, @NonNull FireboltProperties connectionProperties, String formattedStatement, String uri) throws IOException, FireboltException { try { - log.debug("Posting statement with label {} to URI: {}", label, uri); + log.log(Level.FINE, "Posting statement with label {0} to URI: {1}", new Object[] {label, uri}); return postSqlStatement(connectionProperties, formattedStatement, uri, label); } catch (FireboltException exception) { if (exception.getType() == UNAUTHORIZED) { - log.debug("Retrying to post statement with label {} following a 401 status code to URI: {}",label, uri); + log.log(Level.FINE, "Retrying to post statement with label {0} following a 401 status code to URI: {1}", new Object[] {label, uri}); return postSqlStatement(connectionProperties, formattedStatement, uri, label); } else { throw exception; @@ -223,7 +224,7 @@ private void abortRunningDbStatement(String label, FireboltProperties fireboltPr if (e.getType() == ExceptionType.INVALID_REQUEST || e.getType() == ExceptionType.RESOURCE_NOT_FOUND) { // 400 on that request indicates that the statement does not exist // 404 - the same when working against "real" v2 engine - log.warn(e.getMessage()); + log.warning(e.getMessage()); } else { throw e; } diff --git a/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java b/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java index e0ad33118..ee9b12cbe 100644 --- a/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java +++ b/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java @@ -19,7 +19,6 @@ import com.firebolt.jdbc.type.FireboltDataType; import com.firebolt.jdbc.type.array.FireboltArray; import com.firebolt.jdbc.util.PropertyUtil; -import lombok.CustomLog; import lombok.NonNull; import okhttp3.OkHttpClient; @@ -51,15 +50,17 @@ import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; import static java.lang.String.format; import static java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT; import static java.sql.ResultSet.TYPE_FORWARD_ONLY; -@CustomLog public abstract class FireboltConnection extends JdbcBase implements Connection { + private static final Logger log = Logger.getLogger(FireboltConnection.class.getName()); private final FireboltAuthenticationService fireboltAuthenticationService; private final FireboltStatementService fireboltStatementService; protected String httpConnectionUrl; @@ -161,7 +162,7 @@ protected void connect() throws SQLException { } databaseMetaData = retrieveMetaData(); - log.debug("Connection opened"); + log.fine("Connection opened"); } protected abstract void authenticate() throws SQLException; @@ -309,7 +310,7 @@ public void abort(Executor executor) throws SQLException { @Override public void close() { - log.debug("Closing connection"); + log.fine("Closing connection"); synchronized (this) { if (isClosed()) { return; @@ -322,13 +323,13 @@ public void close() { try { statement.close(false); } catch (Exception e) { - log.warn("Could not close statement", e); + log.log(Level.WARNING, "Could not close statement", e); } } statements.clear(); } databaseMetaData = null; - log.debug("Connection closed"); + log.warning("Connection closed"); } protected FireboltProperties extractFireboltProperties(String jdbcUri, Properties connectionProperties) { @@ -425,9 +426,9 @@ private void validateConnection(FireboltProperties fireboltProperties, boolean i // This error cannot be ignored when testing the connection to validate a param. if (ignoreToManyRequestsError && e instanceof FireboltException && ((FireboltException) e).getType() == ExceptionType.TOO_MANY_REQUESTS) { - log.warn("Too many requests are being sent to the server", e); + log.log(Level.WARNING, "Too many requests are being sent to the server", e); } else { - log.warn("Connection is not valid", e); + log.log(Level.WARNING, "Connection is not valid", e); throw e; } } diff --git a/src/main/java/com/firebolt/jdbc/connection/UrlUtil.java b/src/main/java/com/firebolt/jdbc/connection/UrlUtil.java index 1ceecc168..1142403e2 100644 --- a/src/main/java/com/firebolt/jdbc/connection/UrlUtil.java +++ b/src/main/java/com/firebolt/jdbc/connection/UrlUtil.java @@ -1,7 +1,6 @@ package com.firebolt.jdbc.connection; import com.firebolt.jdbc.connection.settings.FireboltSessionProperty; -import lombok.CustomLog; import lombok.experimental.UtilityClass; import java.net.MalformedURLException; @@ -12,15 +11,17 @@ import java.util.Optional; import java.util.Properties; import java.util.TreeMap; +import java.util.logging.Level; +import java.util.logging.Logger; import static java.lang.String.CASE_INSENSITIVE_ORDER; import static java.util.stream.Collectors.toMap; -@CustomLog @UtilityClass public class UrlUtil { public static final String JDBC_PREFIX = "jdbc:firebolt:"; + private static final Logger log = Logger.getLogger(UrlUtil.class.getName()); public static Properties extractProperties(String jdbcUrl) { return parseUriQueryPart(jdbcUrl); @@ -39,7 +40,7 @@ private static Properties parseUriQueryPart(String jdbcConnectionString) { if (keyValueTokens.length == 2) { uriProperties.put(keyValueTokens[0], keyValueTokens[1]); } else { - log.warn("Cannot parse key-pair: {}", keyValue); + log.log(Level.WARNING, "Cannot parse key-pair: {0}", keyValue); } } } diff --git a/src/main/java/com/firebolt/jdbc/connection/settings/FireboltProperties.java b/src/main/java/com/firebolt/jdbc/connection/settings/FireboltProperties.java index 7c8266863..e3ddc9de0 100644 --- a/src/main/java/com/firebolt/jdbc/connection/settings/FireboltProperties.java +++ b/src/main/java/com/firebolt/jdbc/connection/settings/FireboltProperties.java @@ -2,7 +2,6 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.CustomLog; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; @@ -32,7 +31,6 @@ @AllArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true) -@CustomLog public class FireboltProperties { private static final Pattern DB_PATH_PATTERN = Pattern.compile("/?([a-zA-Z0-9_*\\-]+)"); diff --git a/src/main/java/com/firebolt/jdbc/log/FireboltLogger.java b/src/main/java/com/firebolt/jdbc/log/FireboltLogger.java deleted file mode 100644 index 478c4548a..000000000 --- a/src/main/java/com/firebolt/jdbc/log/FireboltLogger.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.firebolt.jdbc.log; - -public interface FireboltLogger { - - void trace(String message); - - void trace(String message, Object... arguments); - - void trace(String message, Throwable t); - - void debug(String message); - - void debug(String message, Object... arguments); - - void debug(String message, Throwable t); - - void info(String message); - - void info(String message, Object... arguments); - - void info(String message, Throwable t); - - void warn(String message); - - void warn(String message, Object... arguments); - - void warn(String message, Throwable t); - - void error(String message); - - void error(String message, Object... arguments); - - void error(String message, Throwable t); - -} diff --git a/src/main/java/com/firebolt/jdbc/log/JDKLogger.java b/src/main/java/com/firebolt/jdbc/log/JDKLogger.java deleted file mode 100644 index ad19f26d5..000000000 --- a/src/main/java/com/firebolt/jdbc/log/JDKLogger.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.firebolt.jdbc.log; - -import java.util.logging.Level; - -public class JDKLogger implements FireboltLogger { - - private final java.util.logging.Logger logger; - - public JDKLogger(String name) { - this.logger = java.util.logging.Logger.getLogger(name); - } - - @Override - public void trace(String message) { - logger.log(Level.FINEST, message); - } - - @Override - public void trace(String message, Object... arguments) { - logger.log(Level.FINEST, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void trace(String message, Throwable t) { - logger.log(Level.FINEST, message, t); - } - - @Override - public void debug(String message) { - logger.log(Level.FINE, message); - } - - @Override - public void debug(String message, Object... arguments) { - logger.log(Level.FINE, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void debug(String message, Throwable t) { - logger.log(Level.FINE, message, t); - } - - @Override - public void info(String message) { - logger.log(Level.INFO, message); - } - - @Override - public void info(String message, Object... arguments) { - logger.log(Level.INFO, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void info(String message, Throwable t) { - logger.log(Level.INFO, message, t); - } - - @Override - public void warn(String message) { - logger.log(Level.WARNING, message); - } - - @Override - public void warn(String message, Object... arguments) { - logger.log(Level.WARNING, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void warn(String message, Throwable t) { - logger.log(Level.WARNING, message, t); - - } - - @Override - public void error(String message) { - logger.log(Level.SEVERE, message); - } - - @Override - public void error(String message, Object... arguments) { - logger.log(Level.SEVERE, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void error(String message, Throwable t) { - logger.log(Level.SEVERE, message, t); - } - - /** - * SLF4J and java.util.logging use a different log format. With SLF4J it is not - * required to have argument indexes in the logs (eg: "log.info("hello {}", - * "world");), but it is required for java.util.logging (eg: "log.info("hello - * {1}", "world");) In this project we use the SLF4J way of logging, which is - * why we need to add the missing indexes. - */ - private String addMissingArgumentsIndexes(String message) { - StringBuilder result = new StringBuilder(); - int argumentIndex = 0; - int i = 0; - while (i < message.length()) { - if (message.charAt(i) == '{' && i < message.length() - 1 && message.charAt(i + 1) == '}') { - result.append(String.format("{%d}", argumentIndex++)); - i++; - } else { - result.append(message.charAt(i)); - } - i++; - } - return result.toString(); - } -} diff --git a/src/main/java/com/firebolt/jdbc/log/SLF4JLogger.java b/src/main/java/com/firebolt/jdbc/log/SLF4JLogger.java deleted file mode 100644 index ba769bbfc..000000000 --- a/src/main/java/com/firebolt/jdbc/log/SLF4JLogger.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.firebolt.jdbc.log; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SLF4JLogger implements FireboltLogger { - - private final Logger logger; - - public SLF4JLogger(String name) { - logger = LoggerFactory.getLogger(name); - } - - @Override - public void trace(String message) { - logger.trace(message); - } - - @Override - public void trace(String message, Object... arguments) { - logger.trace(message, arguments); - } - - @Override - public void trace(String message, Throwable t) { - logger.trace(message, t); - } - - @Override - public void debug(String message) { - logger.debug(message); - } - - @Override - public void debug(String message, Object... arguments) { - logger.debug(message, arguments); - - } - - @Override - public void debug(String message, Throwable t) { - logger.debug(message, t); - } - - @Override - public void info(String message) { - logger.info(message); - } - - @Override - public void info(String message, Object... arguments) { - logger.info(message, arguments); - } - - @Override - public void info(String message, Throwable t) { - logger.info(message, t); - } - - @Override - public void warn(String message) { - logger.warn(message); - } - - @Override - public void warn(String message, Object... arguments) { - logger.warn(message, arguments); - } - - @Override - public void warn(String message, Throwable t) { - logger.warn(message, t); - } - - @Override - public void error(String message) { - logger.error(message); - } - - @Override - public void error(String message, Object... arguments) { - logger.error(message, arguments); - } - - @Override - public void error(String message, Throwable t) { - logger.error(message, t); - } -} diff --git a/src/main/java/com/firebolt/jdbc/metadata/FireboltDatabaseMetadata.java b/src/main/java/com/firebolt/jdbc/metadata/FireboltDatabaseMetadata.java index 1c2be29e9..d231fd273 100644 --- a/src/main/java/com/firebolt/jdbc/metadata/FireboltDatabaseMetadata.java +++ b/src/main/java/com/firebolt/jdbc/metadata/FireboltDatabaseMetadata.java @@ -8,7 +8,6 @@ import com.firebolt.jdbc.resultset.column.Column; import com.firebolt.jdbc.type.FireboltDataType; import com.firebolt.jdbc.util.VersionUtil; -import lombok.CustomLog; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -149,7 +148,6 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; -@CustomLog @SuppressWarnings("java:S6204") // compatibility with JDK 11 public class FireboltDatabaseMetadata implements DatabaseMetaData { diff --git a/src/main/java/com/firebolt/jdbc/resultset/FireboltResultSet.java b/src/main/java/com/firebolt/jdbc/resultset/FireboltResultSet.java index 4da27584a..15e66e79b 100644 --- a/src/main/java/com/firebolt/jdbc/resultset/FireboltResultSet.java +++ b/src/main/java/com/firebolt/jdbc/resultset/FireboltResultSet.java @@ -16,7 +16,6 @@ import com.firebolt.jdbc.type.array.FireboltArray; import com.firebolt.jdbc.type.array.SqlArrayUtil; import com.firebolt.jdbc.util.LoggerUtil; -import lombok.CustomLog; import org.apache.commons.text.StringEscapeUtils; import javax.sql.rowset.serial.SerialBlob; @@ -53,6 +52,8 @@ import java.util.Map; import java.util.TimeZone; import java.util.TreeMap; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -66,10 +67,10 @@ /** * ResultSet for InputStream using the format "TabSeparatedWithNamesAndTypes" */ -@CustomLog public class FireboltResultSet extends JdbcBase implements ResultSet { private static final String FORWARD_ONLY_ERROR = "Cannot call %s() for ResultSet of type TYPE_FORWARD_ONLY"; private static final int DEFAULT_CHAR_BUFFER_SIZE = 8192; // the default of BufferedReader + private static final Logger log = Logger.getLogger(FireboltResultSet.class.getName()); private final BufferedReader reader; private final Map columnNameToColumnNumber; private final FireboltResultSetMetaData resultSetMetaData; @@ -87,7 +88,7 @@ public class FireboltResultSet extends JdbcBase implements ResultSet { public FireboltResultSet(InputStream is, String tableName, String dbName, int bufferSize, boolean isCompressed, FireboltStatement statement, boolean logResultSet) throws SQLException { - log.debug("Creating resultSet..."); + log.fine("Creating resultSet..."); this.statement = statement; if (logResultSet) { is = LoggerUtil.logInputStream(is); @@ -109,10 +110,10 @@ public FireboltResultSet(InputStream is, String tableName, String dbName, int bu columns = next() ? getColumns(fields, currentLine) : new ArrayList<>(); resultSetMetaData = new FireboltResultSetMetaData(dbName, tableName, columns); } catch (Exception e) { - log.error("Could not create ResultSet: {}", e.getMessage(), e); + log.log(Level.SEVERE, "Could not create ResultSet: " + e.getMessage(), e); throw new FireboltException("Cannot read response from DB: error while creating ResultSet ", e); } - log.debug("ResultSet created"); + log.fine("ResultSet created"); } public static FireboltResultSet of(QueryResult queryResult) throws SQLException { diff --git a/src/main/java/com/firebolt/jdbc/resultset/column/Column.java b/src/main/java/com/firebolt/jdbc/resultset/column/Column.java index d0cae2425..f90eae484 100644 --- a/src/main/java/com/firebolt/jdbc/resultset/column/Column.java +++ b/src/main/java/com/firebolt/jdbc/resultset/column/Column.java @@ -1,23 +1,24 @@ package com.firebolt.jdbc.resultset.column; import lombok.Builder; -import lombok.CustomLog; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; +import java.util.logging.Level; +import java.util.logging.Logger; + @Builder @Getter @EqualsAndHashCode @ToString -@CustomLog public final class Column { - + private static final Logger log = Logger.getLogger(Column.class.getName()); private final ColumnType type; private final String columnName; public static Column of(String columnType, String columnName) { - log.debug("Creating column info for column: {} of type: {}", columnName, columnType); + log.log(Level.SEVERE, "Creating column info for column: {0} of type: {1}", new Object[] {columnName, columnType}); return Column.builder().columnName(columnName).type(ColumnType.of(columnType)).build(); } } diff --git a/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java b/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java index 4e1d23a21..c8ddf6737 100644 --- a/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java +++ b/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java @@ -2,7 +2,6 @@ import com.firebolt.jdbc.type.FireboltDataType; import lombok.Builder; -import lombok.CustomLog; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; @@ -17,6 +16,8 @@ import java.util.Optional; import java.util.Set; import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -27,7 +28,6 @@ /** * This class represents a Column type returned by the server */ -@CustomLog @Builder @Value @EqualsAndHashCode @@ -40,6 +40,7 @@ public class ColumnType { private static final Set TIMEZONES = Arrays.stream(TimeZone.getAvailableIDs()) .collect(Collectors.toCollection(HashSet::new)); private static final Pattern COMMA_WITH_SPACES = Pattern.compile("\\s*,\\s*"); + private static final Logger log = Logger.getLogger(ColumnType.class.getName()); @EqualsAndHashCode.Exclude String name; FireboltDataType dataType; @@ -166,7 +167,7 @@ private static TimeZone getTimeZoneFromArguments(@NonNull String[] arguments) { if (TIMEZONES.contains(id)) { timeZone = TimeZone.getTimeZone(timeZoneArgument.replace("\\'", "")); } else { - log.warn("Could not use the timezone returned by the server with the id {} as it is not supported.", id); + log.log(Level.FINE, "Could not use the timezone returned by the server with the id {0} as it is not supported.", id); } } return timeZone; diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java index 0063ca3b8..7ac07132e 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java @@ -1,6 +1,7 @@ package com.firebolt.jdbc.service; import com.firebolt.jdbc.client.authentication.FireboltAuthenticationClient; +import com.firebolt.jdbc.client.config.socket.SocketUtil; import com.firebolt.jdbc.connection.FireboltConnectionTokens; import com.firebolt.jdbc.connection.settings.FireboltProperties; import com.firebolt.jdbc.exception.FireboltException; @@ -12,6 +13,8 @@ import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.logging.Level; +import java.util.logging.Logger; import static java.lang.String.format; import static java.util.Optional.ofNullable; @@ -19,9 +22,9 @@ import static net.jodah.expiringmap.ExpirationPolicy.CREATED; @RequiredArgsConstructor -@CustomLog public class FireboltAuthenticationService { + private static final Logger log = Logger.getLogger(FireboltAuthenticationService.class.getName()); private static final ExpiringMap tokensMap = ExpiringMap.builder() .variableExpiration().build(); private static final long TOKEN_EXPIRATION_OFFSET = 5L; @@ -36,7 +39,7 @@ public FireboltConnectionTokens getConnectionTokens(String host, FireboltPropert synchronized (this) { FireboltConnectionTokens foundToken = tokensMap.get(connectionParams); if (foundToken != null) { - log.debug("Using the token of {} from the cache", host); + log.log(Level.FINE, "Using the token of {} from the cache", host); return foundToken; } FireboltConnectionTokens fireboltConnectionTokens = fireboltAuthenticationClient @@ -46,11 +49,11 @@ public FireboltConnectionTokens getConnectionTokens(String host, FireboltPropert return fireboltConnectionTokens; } } catch (FireboltException e) { - log.error("Failed to connect to Firebolt", e); + log.log(Level.SEVERE, "Failed to connect to Firebolt", e); String msg = ofNullable(e.getErrorMessageFromServer()).map(m -> format(ERROR_MESSAGE_FROM_SERVER, m)).orElse(format(ERROR_MESSAGE, e.getMessage())); throw new FireboltException(msg, e); } catch (Exception e) { - log.error("Failed to connect to Firebolt", e); + log.log(Level.SEVERE, "Failed to connect to Firebolt", e); throw new FireboltException(format(ERROR_MESSAGE, e.getMessage()), e); } } @@ -72,7 +75,7 @@ private long getCachingDurationInSeconds(long expireInSeconds) { */ public void removeConnectionTokens(String host, FireboltProperties loginProperties) throws FireboltException { try { - log.debug("Removing connection token for host {}", host); + log.log(Level.FINE, "Removing connection token for host {0}", host); ConnectParams connectionParams = new ConnectParams(host, loginProperties.getPrincipal(), loginProperties.getSecret()); tokensMap.remove(connectionParams); } catch (NoSuchAlgorithmException e) { diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltEngineApiService.java b/src/main/java/com/firebolt/jdbc/service/FireboltEngineApiService.java index d031fa6e2..38cf92e65 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltEngineApiService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltEngineApiService.java @@ -8,7 +8,6 @@ import com.firebolt.jdbc.connection.Engine; import com.firebolt.jdbc.connection.settings.FireboltProperties; import com.firebolt.jdbc.exception.FireboltException; -import lombok.CustomLog; import lombok.RequiredArgsConstructor; import java.io.IOException; @@ -20,7 +19,6 @@ import static java.util.Optional.ofNullable; @RequiredArgsConstructor -@CustomLog public class FireboltEngineApiService implements FireboltEngineService { private static final Set ENGINE_NOT_READY_STATUSES = Set.of( "ENGINE_STATUS_PROVISIONING_STARTED", "ENGINE_STATUS_PROVISIONING_PENDING", diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltEngineInformationSchemaService.java b/src/main/java/com/firebolt/jdbc/service/FireboltEngineInformationSchemaService.java index f815ecda6..9791628bb 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltEngineInformationSchemaService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltEngineInformationSchemaService.java @@ -4,13 +4,11 @@ import com.firebolt.jdbc.connection.FireboltConnection; import com.firebolt.jdbc.connection.settings.FireboltProperties; import com.firebolt.jdbc.exception.FireboltException; -import lombok.CustomLog; import lombok.RequiredArgsConstructor; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Arrays; import java.util.Collection; import java.util.TreeSet; import java.util.stream.Stream; @@ -20,7 +18,6 @@ import static java.util.stream.Collectors.toCollection; @RequiredArgsConstructor -@CustomLog public class FireboltEngineInformationSchemaService implements FireboltEngineService { private static final String ENGINE_URL = "url"; private static final String STATUS_FIELD = "status"; diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltStatementService.java b/src/main/java/com/firebolt/jdbc/service/FireboltStatementService.java index 7c0563a73..075141899 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltStatementService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltStatementService.java @@ -10,7 +10,6 @@ import com.firebolt.jdbc.statement.rawstatement.QueryRawStatement; import com.firebolt.jdbc.util.CloseableUtil; import com.firebolt.jdbc.util.InputStreamUtil; -import lombok.CustomLog; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -22,7 +21,6 @@ import static java.util.Optional.ofNullable; @RequiredArgsConstructor -@CustomLog public class FireboltStatementService { private static final String UNKNOWN_TABLE_NAME = "unknown"; diff --git a/src/main/java/com/firebolt/jdbc/statement/FireboltStatement.java b/src/main/java/com/firebolt/jdbc/statement/FireboltStatement.java index 38faf2fef..225a17b63 100644 --- a/src/main/java/com/firebolt/jdbc/statement/FireboltStatement.java +++ b/src/main/java/com/firebolt/jdbc/statement/FireboltStatement.java @@ -11,7 +11,6 @@ import com.firebolt.jdbc.exception.FireboltUnsupportedOperationException; import com.firebolt.jdbc.service.FireboltStatementService; import com.firebolt.jdbc.util.CloseableUtil; -import lombok.CustomLog; import java.io.InputStream; import java.sql.Connection; @@ -27,13 +26,16 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import static com.firebolt.jdbc.statement.rawstatement.StatementValidatorFactory.createValidator; +import static java.lang.String.format; import static java.util.stream.Collectors.toCollection; -@CustomLog public class FireboltStatement extends JdbcBase implements Statement { + private static final Logger log = Logger.getLogger(FireboltStatement.class.getName()); private final FireboltStatementService statementService; private final FireboltProperties sessionProperties; private final FireboltConnection connection; @@ -54,7 +56,7 @@ public FireboltStatement(FireboltStatementService statementService, FireboltProp this.statementService = statementService; this.sessionProperties = sessionProperties; this.connection = connection; - log.debug("Created Statement"); + log.fine("Created Statement"); } @Override @@ -108,11 +110,10 @@ private Optional execute(StatementInfoWrapper statementInfoWrapper, b } InputStream inputStream = null; try { - log.info("Executing the statement with label {} : {}", statementInfoWrapper.getLabel(), - statementInfoWrapper.getSql()); + log.log(Level.INFO, "Executing the statement with label {0} : {1}", new Object[] {statementInfoWrapper.getLabel(), statementInfoWrapper.getSql()}); if (statementInfoWrapper.getType() == StatementType.PARAM_SETTING) { connection.addProperty(statementInfoWrapper.getParam()); - log.debug("The property from the query {} was stored", runningStatementLabel); + log.log(Level.FINE, "The property from the query {0} was stored", runningStatementLabel); } else { Optional currentRs = statementService.execute(statementInfoWrapper, sessionProperties, isStandardSql, this); if (currentRs.isPresent()) { @@ -121,12 +122,11 @@ private Optional execute(StatementInfoWrapper statementInfoWrapper, b } else { currentUpdateCount = 0; } - log.info("The query with the label {} was executed with success", runningStatementLabel); + log.log(Level.INFO, "The query with the label {0} was executed with success", runningStatementLabel); } } catch (Exception ex) { CloseableUtil.close(inputStream); - log.error(String.format("An error happened while executing the statement with the id %s", - runningStatementLabel), ex); + log.log(Level.SEVERE, ex, () -> format("An error happened while executing the statement with the id %s", runningStatementLabel)); throw ex; } finally { runningStatementLabel = null; @@ -139,7 +139,7 @@ private Optional execute(StatementInfoWrapper statementInfoWrapper, b } } } else { - log.warn("Aborted query with id {}", statementInfoWrapper.getLabel()); + log.log(Level.FINE, "Aborted query with id {0}", statementInfoWrapper.getLabel()); } return Optional.ofNullable(resultSet); } @@ -174,7 +174,7 @@ public void cancel() throws SQLException { private void abortStatementRunningOnFirebolt(String statementLabel) throws SQLException { try { statementService.abortStatement(statementLabel, sessionProperties); - log.debug("Statement with label {} was aborted", statementLabel); + log.log(Level.FINE, "Statement with label {0} was aborted", statementLabel); } catch (FireboltException e) { throw e; } catch (Exception e) { @@ -256,7 +256,7 @@ public int getMaxRows() throws SQLException { @Override public void setMaxRows(int max) throws SQLException { if (max < 0) { - throw new FireboltException(String.format("Illegal maxRows value: %d", max)); + throw new FireboltException(format("Illegal maxRows value: %d", max)); } maxRows = max; } @@ -288,7 +288,7 @@ public void close(boolean removeFromConnection) throws SQLException { connection.removeClosedStatement(this); } cancel(); - log.debug("Statement closed"); + log.fine("Statement closed"); } @Override diff --git a/src/main/java/com/firebolt/jdbc/statement/StatementResultWrapper.java b/src/main/java/com/firebolt/jdbc/statement/StatementResultWrapper.java index c82031324..a67cbd1d6 100644 --- a/src/main/java/com/firebolt/jdbc/statement/StatementResultWrapper.java +++ b/src/main/java/com/firebolt/jdbc/statement/StatementResultWrapper.java @@ -1,16 +1,16 @@ package com.firebolt.jdbc.statement; -import java.io.Closeable; -import java.sql.ResultSet; +import lombok.Data; import javax.annotation.Nullable; - -import lombok.CustomLog; -import lombok.Data; +import java.io.Closeable; +import java.sql.ResultSet; +import java.util.logging.Level; +import java.util.logging.Logger; @Data -@CustomLog public class StatementResultWrapper implements Closeable { + private static final Logger log = Logger.getLogger(StatementResultWrapper.class.getName()); private ResultSet resultSet; private int updateCount; private StatementInfoWrapper statementInfoWrapper; @@ -29,7 +29,7 @@ public void close() { resultSet.close(); } } catch (Exception e) { - log.warn("Could not close ResultSet", e); + log.log(Level.WARNING, "Could not close ResultSet", e); } if (next != null) { next.close(); diff --git a/src/main/java/com/firebolt/jdbc/statement/StatementUtil.java b/src/main/java/com/firebolt/jdbc/statement/StatementUtil.java index f26c74f49..fca7e8bee 100644 --- a/src/main/java/com/firebolt/jdbc/statement/StatementUtil.java +++ b/src/main/java/com/firebolt/jdbc/statement/StatementUtil.java @@ -4,7 +4,6 @@ import com.firebolt.jdbc.statement.rawstatement.RawStatementWrapper; import com.firebolt.jdbc.statement.rawstatement.SetParamRawStatement; import com.firebolt.jdbc.util.StringUtil; -import lombok.CustomLog; import lombok.NonNull; import lombok.experimental.UtilityClass; @@ -15,17 +14,19 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; @UtilityClass -@CustomLog public class StatementUtil { private static final String SET_PREFIX = "set"; private static final Pattern SET_WITH_SPACE_REGEX = Pattern.compile(SET_PREFIX + " ", Pattern.CASE_INSENSITIVE); private static final String[] SELECT_KEYWORDS = new String[] { "show", "select", "describe", "exists", "explain", "with", "call" }; + private static final Logger log = Logger.getLogger(StatementUtil.class.getName()); /** * Returns true if the statement is a query (eg: SELECT, SHOW). @@ -180,7 +181,7 @@ public Map getParamMarketsPositions(String sql) { public Entry, Optional> extractDbNameAndTableNamePairFromCleanQuery(String cleanSql) { Optional from = Optional.empty(); if (isQuery(cleanSql)) { - log.debug("Extracting DB and Table name for SELECT: {}", cleanSql); + log.log(Level.FINE, "Extracting DB and Table name for SELECT: {0}", cleanSql); String withoutQuotes = cleanSql.replace("'", "").trim(); String withoutQuotesUpperCase = withoutQuotes.toUpperCase(); if (withoutQuotesUpperCase.startsWith("SELECT")) { @@ -193,7 +194,7 @@ public Entry, Optional> extractDbNameAndTableNamePairFr } else if (withoutQuotesUpperCase.startsWith("SHOW")) { from = Optional.empty(); // Depends on the information requested } else { - log.debug("Could not find table name for query {}. This may happen when there is no table.", cleanSql); + log.log(Level.FINE, "Could not find table name for query {0}. This may happen when there is no table.", cleanSql); } } return Map.entry(extractDbNameFromFromPartOfTheQuery(from.orElse(null)), diff --git a/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java b/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java index e6eafb6da..0894cae30 100644 --- a/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java +++ b/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java @@ -14,7 +14,6 @@ import com.firebolt.jdbc.statement.rawstatement.RawStatementWrapper; import com.firebolt.jdbc.type.JavaTypeToFireboltSQLString; import com.firebolt.jdbc.util.InputStreamUtil; -import lombok.CustomLog; import lombok.NonNull; import java.io.IOException; @@ -43,6 +42,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import static com.firebolt.jdbc.statement.StatementUtil.replaceParameterMarksWithValues; import static com.firebolt.jdbc.statement.rawstatement.StatementValidatorFactory.createValidator; @@ -51,9 +52,8 @@ import static java.sql.Types.NUMERIC; import static java.sql.Types.VARBINARY; -@CustomLog public class FireboltPreparedStatement extends FireboltStatement implements PreparedStatement { - + private static final Logger log = Logger.getLogger(FireboltPreparedStatement.class.getName()); private final RawStatementWrapper rawStatement; private final List> rows; private Map providedParameters; @@ -65,7 +65,7 @@ public FireboltPreparedStatement(FireboltStatementService statementService, Fire public FireboltPreparedStatement(FireboltStatementService statementService, FireboltProperties sessionProperties, FireboltConnection connection, String sql) { super(statementService, sessionProperties, connection); - log.debug("Populating PreparedStatement object for SQL: {}", sql); + log.log(Level.SEVERE, "Populating PreparedStatement object for SQL: {0}", sql); this.providedParameters = new HashMap<>(); this.rawStatement = StatementUtil.parseToRawStatementWrapper(sql); rawStatement.getSubStatements().forEach(statement -> createValidator(statement, connection).validate(statement)); @@ -261,7 +261,7 @@ public void setArray(int parameterIndex, Array x) throws SQLException { @Override public int[] executeBatch() throws SQLException { validateStatementIsNotClosed(); - log.debug("Executing batch for statement: {}", rawStatement); + log.log(Level.SEVERE, "Executing batch for statement: {0}", rawStatement); List inserts = new ArrayList<>(); int[] result = new int[rows.size()]; for (Map row : rows) { diff --git a/src/main/java/com/firebolt/jdbc/statement/rawstatement/RawStatementWrapper.java b/src/main/java/com/firebolt/jdbc/statement/rawstatement/RawStatementWrapper.java index 656f26381..75e967dfb 100644 --- a/src/main/java/com/firebolt/jdbc/statement/rawstatement/RawStatementWrapper.java +++ b/src/main/java/com/firebolt/jdbc/statement/rawstatement/RawStatementWrapper.java @@ -1,13 +1,11 @@ package com.firebolt.jdbc.statement.rawstatement; -import lombok.CustomLog; import lombok.Value; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -@CustomLog @Value public class RawStatementWrapper { diff --git a/src/main/java/com/firebolt/jdbc/type/BaseType.java b/src/main/java/com/firebolt/jdbc/type/BaseType.java index e397fcba2..7d401678d 100644 --- a/src/main/java/com/firebolt/jdbc/type/BaseType.java +++ b/src/main/java/com/firebolt/jdbc/type/BaseType.java @@ -24,7 +24,6 @@ import static com.firebolt.jdbc.type.array.SqlArrayUtil.hexStringToByteArray; /** This class contains the java types the Firebolt datatypes are mapped to */ -@CustomLog public enum BaseType { LONG(Long.class, conversion -> Long.parseLong(checkInfinity(conversion.getValue()))), INTEGER(Integer.class, conversion -> Integer.parseInt(checkInfinity(conversion.getValue()))), diff --git a/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java b/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java index 7ed7d81df..cd706a850 100644 --- a/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java +++ b/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java @@ -5,7 +5,6 @@ import com.firebolt.jdbc.type.FireboltDataType; import com.firebolt.jdbc.type.JavaTypeToFireboltSQLString; import com.firebolt.jdbc.util.StringUtil; -import lombok.CustomLog; import lombok.NonNull; import javax.annotation.Nullable; @@ -15,6 +14,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Stream; import static java.lang.String.format; @@ -23,15 +24,15 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; -@CustomLog public class SqlArrayUtil { private static final Map formatMarkers = Map.of( '[', new Markers('[', ']', '\'', '\''), '{', new Markers('{', '}', '"', '\'') ); + public static final String BYTE_ARRAY_PREFIX = "\\x"; + private static final Logger log = Logger.getLogger(SqlArrayUtil.class.getName()); private final ColumnType columnType; private final Markers markers; - public static final String BYTE_ARRAY_PREFIX = "\\x"; private static final class Markers { private final char leftArrayBracket; @@ -53,7 +54,7 @@ public SqlArrayUtil(ColumnType columnType, Markers markers) { } public static FireboltArray transformToSqlArray(String value, ColumnType columnType) throws SQLException { - log.debug("Transformer array with value {} and type {}", value, columnType); + log.log(Level.FINE, "Transformer array with value {0} and type {1}", new Object[] {value, columnType}); if (isNullValue(value)) { return null; } diff --git a/src/main/java/com/firebolt/jdbc/type/date/SqlDateUtil.java b/src/main/java/com/firebolt/jdbc/type/date/SqlDateUtil.java index 5a77bfb10..1595c51fb 100644 --- a/src/main/java/com/firebolt/jdbc/type/date/SqlDateUtil.java +++ b/src/main/java/com/firebolt/jdbc/type/date/SqlDateUtil.java @@ -17,7 +17,6 @@ import java.util.function.Function; @UtilityClass -@CustomLog public class SqlDateUtil { public static final long ONE_DAY_MILLIS = 86400000L; diff --git a/src/main/java/com/firebolt/jdbc/util/CloseableUtil.java b/src/main/java/com/firebolt/jdbc/util/CloseableUtil.java index 660576645..39de66c2e 100644 --- a/src/main/java/com/firebolt/jdbc/util/CloseableUtil.java +++ b/src/main/java/com/firebolt/jdbc/util/CloseableUtil.java @@ -2,13 +2,15 @@ import java.io.Closeable; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; import lombok.CustomLog; import lombok.experimental.UtilityClass; -@CustomLog @UtilityClass public class CloseableUtil { + private static final Logger log = Logger.getLogger(CloseableUtil.class.getName()); /** * Closes the {@link Closeable} and log any potential {@link IOException} @@ -20,7 +22,7 @@ public void close(Closeable closeable) { try { closeable.close(); } catch (IOException e) { - log.error("An error happened while closing the closeable: {}", e.getMessage()); + log.log(Level.SEVERE, "An error happened while closing the closeable: {0}", e.getMessage()); } } } diff --git a/src/main/java/com/firebolt/jdbc/util/InputStreamUtil.java b/src/main/java/com/firebolt/jdbc/util/InputStreamUtil.java index 8518f4a37..a1e66e03c 100644 --- a/src/main/java/com/firebolt/jdbc/util/InputStreamUtil.java +++ b/src/main/java/com/firebolt/jdbc/util/InputStreamUtil.java @@ -1,18 +1,19 @@ package com.firebolt.jdbc.util; -import lombok.CustomLog; import lombok.experimental.UtilityClass; import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.util.logging.Level; +import java.util.logging.Logger; @UtilityClass -@CustomLog public class InputStreamUtil { private static final int K_BYTE = 1024; private static final int BUFFER_SIZE = 8 * K_BYTE; + private static final Logger log = Logger.getLogger(InputStreamUtil.class.getName()); /** * Read all bytes from the input stream if the stream is not null @@ -25,7 +26,7 @@ public void readAllBytes(@Nullable InputStream is) { try { if (is.read() == -1) break; } catch (IOException e) { - log.warn("Could not read entire input stream for non query statement", e); + log.log(Level.WARNING, "Could not read entire input stream for non query statement", e); } } } diff --git a/src/main/java/com/firebolt/jdbc/util/LoggerUtil.java b/src/main/java/com/firebolt/jdbc/util/LoggerUtil.java index 3092885a3..b25966a35 100644 --- a/src/main/java/com/firebolt/jdbc/util/LoggerUtil.java +++ b/src/main/java/com/firebolt/jdbc/util/LoggerUtil.java @@ -1,38 +1,39 @@ package com.firebolt.jdbc.util; -import java.io.*; +import com.firebolt.FireboltDriver; +import lombok.experimental.UtilityClass; +import org.slf4j.bridge.SLF4JBridgeHandler; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; -import com.firebolt.jdbc.log.FireboltLogger; -import com.firebolt.jdbc.log.JDKLogger; -import com.firebolt.jdbc.log.SLF4JLogger; - -import lombok.CustomLog; -import lombok.experimental.UtilityClass; - @UtilityClass -@CustomLog public class LoggerUtil { - private static Boolean slf4jAvailable; - - /** - * Provides a {@link FireboltLogger} based on whether SLF4J is available or not. - * - * @param name logger name - * @return a {@link FireboltLogger} - */ - public static FireboltLogger getLogger(String name) { - if (slf4jAvailable == null) { - slf4jAvailable = isSlf4jJAvailable(); - } + private static final boolean slf4jAvailable = isSlf4jJAvailable(); + private static final Logger root = initRootLogger(); + private static final Logger log = Logger.getLogger(LoggerUtil.class.getName()); + private Logger initRootLogger() { + Logger root = Logger.getLogger(FireboltDriver.class.getPackageName()); if (slf4jAvailable) { - return new SLF4JLogger(name); - } else { - return new JDKLogger(name); + synchronized (root) { + root.addHandler(new SLF4JBridgeHandler()); + root.setLevel(Level.ALL); + } } + return root; + } + + public static Logger getRootLogger() { + return root; } /** @@ -58,7 +59,7 @@ public InputStream logInputStream(InputStream is) { log.info("======================================"); return new ByteArrayInputStream(baos.toByteArray()); } catch (Exception ex) { - log.warn("Could not log the stream", ex); + log.log(Level.WARNING, "Could not log the stream", ex); } return new ByteArrayInputStream(baos.toByteArray()); } diff --git a/src/main/java/com/firebolt/jdbc/util/PropertyUtil.java b/src/main/java/com/firebolt/jdbc/util/PropertyUtil.java index ae1c90df5..74fd93b52 100644 --- a/src/main/java/com/firebolt/jdbc/util/PropertyUtil.java +++ b/src/main/java/com/firebolt/jdbc/util/PropertyUtil.java @@ -18,7 +18,6 @@ import static com.firebolt.jdbc.connection.UrlUtil.extractProperties; import static com.firebolt.jdbc.connection.settings.FireboltSessionProperty.getNonDeprecatedProperties; -@CustomLog @UtilityClass public class PropertyUtil { diff --git a/src/main/java/com/firebolt/jdbc/util/VersionUtil.java b/src/main/java/com/firebolt/jdbc/util/VersionUtil.java index 063015272..4c70c905d 100644 --- a/src/main/java/com/firebolt/jdbc/util/VersionUtil.java +++ b/src/main/java/com/firebolt/jdbc/util/VersionUtil.java @@ -8,15 +8,17 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Arrays; import java.util.Enumeration; import java.util.Properties; import java.util.jar.Attributes.Name; import java.util.jar.Manifest; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @UtilityClass -@CustomLog public class VersionUtil { private static final Pattern VERSION_PATTERN = Pattern.compile("^\\s*(\\d+)\\.(\\d+).*"); @@ -27,13 +29,14 @@ public class VersionUtil { private static String driverVersion = "3.0.4"; private static String specificationVersion = "4.3"; + private static final Logger log = Logger.getLogger(VersionUtil.class.getName()); static { try { retrieveVersionInfo(); - log.info("Firebolt driver version used: {}", driverVersion); + log.log(Level.INFO, "Firebolt driver version used: {0}", driverVersion); } catch (IOException e) { - log.error("Could not get Project Version defined in the build.gradle file", e); + log.log(Level.SEVERE, "Could not get Project Version defined in the build.gradle file", e); } } diff --git a/src/test/java/com/firebolt/FireboltDriverTest.java b/src/test/java/com/firebolt/FireboltDriverTest.java index d690969e1..0122fa15f 100644 --- a/src/test/java/com/firebolt/FireboltDriverTest.java +++ b/src/test/java/com/firebolt/FireboltDriverTest.java @@ -12,12 +12,12 @@ import java.sql.Connection; import java.sql.DriverPropertyInfo; import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import java.util.logging.Logger; import java.util.stream.Collector; import java.util.stream.Collectors; @@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mockConstruction; class FireboltDriverTest { @@ -79,7 +78,8 @@ void acceptsURL(String url, boolean expected) { @Test void getParentLogger() { - assertThrows(SQLFeatureNotSupportedException.class, () -> new FireboltDriver().getParentLogger()); + Logger logger = new FireboltDriver().getParentLogger(); + assertNotNull(logger); } @Test diff --git a/src/test/java/com/firebolt/jdbc/log/JDKLoggerTest.java b/src/test/java/com/firebolt/jdbc/log/JDKLoggerTest.java deleted file mode 100644 index a9ba09cc6..000000000 --- a/src/test/java/com/firebolt/jdbc/log/JDKLoggerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.firebolt.jdbc.log; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -class JDKLoggerTest { - - @Test - void shouldLogWithCorrectLevel() { - try (MockedStatic mockedLogger = Mockito.mockStatic(Logger.class)) { - Logger logger = mock(Logger.class); - mockedLogger.when(() -> java.util.logging.Logger.getLogger(any())).thenReturn(logger); - JDKLogger jdkLogger = new JDKLogger("myTest"); - jdkLogger.debug("This is a debug log"); - jdkLogger.warn("This is a warning log"); - jdkLogger.error("This is an error log"); - jdkLogger.trace("This is a trace log"); - verify(logger).log(Level.FINE, "This is a debug log"); - verify(logger).log(Level.WARNING, "This is a warning log"); - verify(logger).log(Level.SEVERE, "This is an error log"); - verify(logger).log(Level.FINEST, "This is a trace log"); - } - } - - @Test - void shouldLogWithCorrectArgumentIndexes() { - try (MockedStatic mockedLogger = Mockito.mockStatic(Logger.class)) { - Logger logger = mock(Logger.class); - mockedLogger.when(() -> java.util.logging.Logger.getLogger(any())).thenReturn(logger); - JDKLogger jdkLogger = new JDKLogger("myTest"); - jdkLogger.debug("This debug log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - jdkLogger.warn("This warning log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - jdkLogger.error("This error log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - jdkLogger.trace("This trace log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - Object[] args = new Object[] { "arg1", "arg2", "arg3" }; - verify(logger).log(Level.FINE, "This debug log has some arguments: {0}, {1}, {2}", args); - verify(logger).log(Level.WARNING, "This warning log has some arguments: {0}, {1}, {2}", args); - verify(logger).log(Level.SEVERE, "This error log has some arguments: {0}, {1}, {2}", args); - verify(logger).log(Level.FINEST, "This trace log has some arguments: {0}, {1}, {2}", args); - } - } - - @Test - void shouldLogWithThrowable() { - try (MockedStatic mockedLogger = Mockito.mockStatic(Logger.class)) { - Logger logger = mock(Logger.class); - mockedLogger.when(() -> java.util.logging.Logger.getLogger(any())).thenReturn(logger); - JDKLogger jdkLogger = new JDKLogger("myTest"); - IllegalArgumentException illegalArgumentException = new IllegalArgumentException(); - jdkLogger.debug("This debug log has an exception", illegalArgumentException); - jdkLogger.warn("This warning log has an exception", illegalArgumentException); - jdkLogger.error("This error log has an exception", illegalArgumentException); - jdkLogger.trace("This trace log has an exception", illegalArgumentException); - verify(logger).log(Level.FINE, "This debug log has an exception", illegalArgumentException); - verify(logger).log(Level.WARNING, "This warning log has an exception", illegalArgumentException); - verify(logger).log(Level.SEVERE, "This error log has an exception", illegalArgumentException); - verify(logger).log(Level.FINEST, "This trace log has an exception", illegalArgumentException); - } - } -} \ No newline at end of file diff --git a/src/test/java/com/firebolt/jdbc/log/LogLevelExample.java b/src/test/java/com/firebolt/jdbc/log/LogLevelExample.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/test/java/com/firebolt/jdbc/log/SLF4JLoggerTest.java b/src/test/java/com/firebolt/jdbc/log/SLF4JLoggerTest.java deleted file mode 100644 index 6b51d0beb..000000000 --- a/src/test/java/com/firebolt/jdbc/log/SLF4JLoggerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.firebolt.jdbc.log; - -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class SLF4JLoggerTest { - - @Test - void shouldLogWithCorrectLevel() { - try (MockedStatic mockedLoggerFactory = Mockito.mockStatic(LoggerFactory.class)) { - Logger logger = mock(Logger.class); - mockedLoggerFactory.when(() -> LoggerFactory.getLogger(anyString())).thenReturn(logger); - SLF4JLogger slf4JLogger = new SLF4JLogger("logger"); - slf4JLogger.debug("This is a debug log"); - slf4JLogger.warn("This is a warning log"); - slf4JLogger.error("This is an error log"); - slf4JLogger.trace("This is a trace log"); - verify(logger).debug("This is a debug log"); - verify(logger).warn("This is a warning log"); - verify(logger).error("This is an error log"); - verify(logger).trace("This is a trace log"); - } - } - - @Test - void shouldLogWithArguments() { - try (MockedStatic mockedLoggerFactory = Mockito.mockStatic(LoggerFactory.class)) { - Logger logger = mock(Logger.class); - mockedLoggerFactory.when(() -> LoggerFactory.getLogger(anyString())).thenReturn(logger); - SLF4JLogger slf4JLogger = new SLF4JLogger("logger"); - slf4JLogger.debug("This debug log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - slf4JLogger.warn("This warning log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - slf4JLogger.error("This error log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - slf4JLogger.trace("This trace log has some arguments: {}, {}, {}", "arg1", "arg2", "arg3"); - Object[] args = new Object[] { "arg1", "arg2", "arg3" }; - verify(logger).debug("This debug log has some arguments: {}, {}, {}", args); - verify(logger).warn("This warning log has some arguments: {}, {}, {}", args); - verify(logger).error("This error log has some arguments: {}, {}, {}", args); - verify(logger).trace("This trace log has some arguments: {}, {}, {}", args); - } - } - - @Test - void shouldLogWithThrowable() { - try (MockedStatic mockedLoggerFactory = Mockito.mockStatic(LoggerFactory.class)) { - Logger logger = mock(Logger.class); - mockedLoggerFactory.when(() -> LoggerFactory.getLogger(anyString())).thenReturn(logger); - SLF4JLogger slf4JLogger = new SLF4JLogger("logger"); - IllegalArgumentException illegalArgumentException = new IllegalArgumentException(); - slf4JLogger.debug("This debug log has an exception", illegalArgumentException); - slf4JLogger.warn("This warning log has an exception", illegalArgumentException); - slf4JLogger.error("This error log has an exception", illegalArgumentException); - slf4JLogger.trace("This trace log has an exception", illegalArgumentException); - verify(logger).debug("This debug log has an exception", illegalArgumentException); - verify(logger).warn("This warning log has an exception", illegalArgumentException); - verify(logger).error("This error log has an exception", illegalArgumentException); - verify(logger).trace("This trace log has an exception", illegalArgumentException); - } - } - -} \ No newline at end of file diff --git a/src/test/java/com/firebolt/jdbc/util/LoggerUtilTest.java b/src/test/java/com/firebolt/jdbc/util/LoggerUtilTest.java index 7b334070e..245198ee8 100644 --- a/src/test/java/com/firebolt/jdbc/util/LoggerUtilTest.java +++ b/src/test/java/com/firebolt/jdbc/util/LoggerUtilTest.java @@ -1,23 +1,23 @@ package com.firebolt.jdbc.util; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - import org.junit.jupiter.api.Test; - -import com.firebolt.jdbc.log.FireboltLogger; -import com.firebolt.jdbc.log.SLF4JLogger; +import org.slf4j.bridge.SLF4JBridgeHandler; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.logging.Logger; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class LoggerUtilTest { @Test void shouldGetSLF4JLoggerWhenAvailable() { - FireboltLogger fireboltLogger = LoggerUtil.getLogger("myLogger"); + Logger fireboltLogger = LoggerUtil.getRootLogger(); // Should be true since SLF4J is available - assertTrue(fireboltLogger instanceof SLF4JLogger); + assertTrue(Arrays.stream(fireboltLogger.getHandlers()).anyMatch(handler -> handler instanceof SLF4JBridgeHandler)); } @Test