From 3261cf599c42301b495a3677d791eb074e4f40fd Mon Sep 17 00:00:00 2001 From: Anton Gozhiy Date: Mon, 2 May 2022 21:58:54 +0300 Subject: [PATCH] Changed logger implementation from log4j to slf4j w/ logback --- conf/logback.xml | 64 +++++++++++++++++++ framework/pom.xml | 44 +++++++++++-- .../drill/test/framework/ConnectionPool.java | 6 +- .../drill/test/framework/DBMetaData.java | 6 +- .../drill/test/framework/DrillRMConfig.java | 5 +- .../drill/test/framework/DrillTestJdbc.java | 14 ++-- .../drill/test/framework/DrillTestOdbc.java | 5 +- .../drill/test/framework/DrillTestScript.java | 21 ++---- .../drill/test/framework/TestDriver.java | 11 ++-- .../drill/test/framework/TestVerifier.java | 5 +- .../apache/drill/test/framework/Utils.java | 7 +- .../DrillTestFrameworkUnitTests.java | 7 +- .../framework/common/DrillJavaTestBase.java | 5 +- .../QueueSelectionTests.java | 5 +- 14 files changed, 149 insertions(+), 56 deletions(-) create mode 100644 conf/logback.xml diff --git a/conf/logback.xml b/conf/logback.xml new file mode 100644 index 00000000..91004fb4 --- /dev/null +++ b/conf/logback.xml @@ -0,0 +1,64 @@ + + + + + + + + logs/drill.log.%d{yyyy-MM-dd-HH} + + + %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + + + + + + System.out + + %m%n + + + + + + System.out + + %m%n + + + + + + + + + + + + + + + + + + + diff --git a/framework/pom.xml b/framework/pom.xml index e57a1782..5bc65365 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -7,7 +7,8 @@ 1.0.0-SNAPSHOT 6.4 - 1.2.17 + 1.7.26 + 1.2.9 2.10.0 30.1.1-jre 2.0.0-SNAPSHOT @@ -38,21 +39,46 @@ org.ojai ojai 1.1 + + + org.slf4j + slf4j-api + + org.apache.zookeeper zookeeper 3.4.14 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + + + org.slf4j + slf4j-api + ${slf4j.version} - log4j - log4j - ${log4j.version} + ch.qos.logback + logback-classic + ${logback.version} - log4j - apache-log4j-extras - ${log4j.version} + ch.qos.logback + logback-core + ${logback.version} junit @@ -92,6 +118,10 @@ org.slf4j slf4j-log4j12 + + log4j + log4j + org.codehaus.jackson jackson-mapper-asl diff --git a/framework/src/main/java/org/apache/drill/test/framework/ConnectionPool.java b/framework/src/main/java/org/apache/drill/test/framework/ConnectionPool.java index 6eca0597..e5d57059 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/ConnectionPool.java +++ b/framework/src/main/java/org/apache/drill/test/framework/ConnectionPool.java @@ -19,7 +19,9 @@ import com.google.common.collect.Queues; import com.google.common.annotations.VisibleForTesting; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -29,7 +31,7 @@ import java.util.Queue; public class ConnectionPool implements AutoCloseable { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private final Map> connections; private Properties connectionProperties; diff --git a/framework/src/main/java/org/apache/drill/test/framework/DBMetaData.java b/framework/src/main/java/org/apache/drill/test/framework/DBMetaData.java index d3b883b3..9d643c23 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DBMetaData.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DBMetaData.java @@ -17,17 +17,19 @@ */ package org.apache.drill.test.framework; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.sql.SQLException; import java.sql.DatabaseMetaData; -import org.apache.log4j.Logger; /** * Retrieves DataBase MetaData. */ public class DBMetaData { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private DatabaseMetaData md = null; public DBMetaData(DatabaseMetaData md) { this.md = md; diff --git a/framework/src/main/java/org/apache/drill/test/framework/DrillRMConfig.java b/framework/src/main/java/org/apache/drill/test/framework/DrillRMConfig.java index 3c97fc82..f5aef855 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DrillRMConfig.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DrillRMConfig.java @@ -9,7 +9,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.typesafe.config.ConfigFactory; import com.typesafe.config.ConfigRenderOptions; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -24,7 +25,7 @@ * Represents a Drill RM Resource Pool configuration. */ public class DrillRMConfig implements DrillConfigRenderer { - private static final Logger LOG = Logger.getLogger(DrillRMConfig.class); + private static final Logger LOG = LoggerFactory.getLogger(DrillRMConfig.class); //Resource Pool Configurations public static final String RESOURCE_POOL_NAME_KEY = "pool_name"; public static final String MEMORY_KEY = "memory"; diff --git a/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java b/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java index 18e31073..701e25b6 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java @@ -20,10 +20,11 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import org.apache.drill.test.framework.TestCaseModeler.TestMatrix; +import org.apache.drill.test.framework.TestVerifier.PlanVerificationException; import org.apache.drill.test.framework.TestVerifier.TestStatus; import org.apache.drill.test.framework.TestVerifier.VerificationException; -import org.apache.drill.test.framework.TestVerifier.PlanVerificationException; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedWriter; import java.io.File; @@ -33,14 +34,13 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.sql.Types; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; public class DrillTestJdbc implements DrillTest { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private static final String LINE_BREAK = "------------------------------------------------------------------------"; private ConnectionPool connectionPool; @@ -248,7 +248,7 @@ private void executeQuery(String query) throws IOException, SQLException { } LOG.debug("Result set data types:"); - LOG.debug(Utils.getTypesInStrings(columnTypes)); + LOG.debug(Utils.getTypesInStrings(columnTypes).toString()); if (resultSet != null) { while (resultSet.next()) { @@ -258,7 +258,7 @@ private void executeQuery(String query) throws IOException, SQLException { } } } catch (IllegalArgumentException | IllegalAccessException | IOException e1) { - LOG.warn(e1); + LOG.warn(e1.getMessage(), e1); } finally { doneProcessingResultSet.set(true); if (resultSet != null) { @@ -322,7 +322,7 @@ private void executeLimitZeroQuery(String query) throws IOException, SQLExceptio : new VerificationException(exception + "\n" + msg); } } catch (IllegalArgumentException | IllegalAccessException e1) { - LOG.warn(e1); + LOG.warn(e1.getMessage(), e1); } finally { if (resultSet != null) resultSet.close(); if (writer != null) writer.close(); diff --git a/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java b/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java index b1830e5d..220db6f9 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java @@ -23,7 +23,8 @@ import org.apache.drill.test.framework.TestVerifier.TestStatus; import org.apache.drill.test.framework.TestVerifier.VerificationException; import org.apache.drill.test.framework.TestVerifier.PlanVerificationException; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -42,7 +43,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class DrillTestOdbc implements DrillTest{ - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private String query = null; private String outputFilename; private volatile TestStatus testStatus = TestStatus.PENDING; diff --git a/framework/src/main/java/org/apache/drill/test/framework/DrillTestScript.java b/framework/src/main/java/org/apache/drill/test/framework/DrillTestScript.java index 1933f426..664ecf6b 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DrillTestScript.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DrillTestScript.java @@ -18,28 +18,15 @@ package org.apache.drill.test.framework; import com.google.common.base.Stopwatch; -import com.google.common.collect.Lists; import org.apache.drill.test.framework.TestCaseModeler.TestMatrix; import org.apache.drill.test.framework.TestVerifier.TestStatus; -import org.apache.drill.test.framework.TestVerifier.VerificationException; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.concurrent.atomic.AtomicBoolean; public class DrillTestScript implements DrillTest { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private String query; private String outputFilename; private volatile TestStatus testStatus = TestStatus.PENDING; @@ -77,7 +64,7 @@ public void run() { try { cmdConsOut = Utils.execCmd(command); - LOG.info(cmdConsOut); + LOG.info(cmdConsOut.toString()); switch (cmdConsOut.exitCode) { case 0: diff --git a/framework/src/main/java/org/apache/drill/test/framework/TestDriver.java b/framework/src/main/java/org/apache/drill/test/framework/TestDriver.java index c7998ba8..b0337a57 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/TestDriver.java +++ b/framework/src/main/java/org/apache/drill/test/framework/TestDriver.java @@ -30,9 +30,10 @@ import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; import org.apache.hadoop.mapred.FileAlreadyExistsException; -import org.apache.log4j.Logger; import org.ojai.Document; import org.ojai.json.Json; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -59,7 +60,7 @@ import java.util.Set; public class TestDriver { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private Connection connection = null; public static String commitId, version; private String[] injectionKeys = {"DRILL_VERSION"}; @@ -680,7 +681,7 @@ public void setup() throws IOException, InterruptedException, URISyntaxException injections.put(injectionKeys[i], version); break; default: - LOG.fatal("Injection parameter not recognized!"); + LOG.error("Injection parameter not recognized!"); } } connectionPool.releaseConnection(connection); @@ -1064,7 +1065,7 @@ private void runGenerateScript(DataSource datasource) { CmdConsOut cmdConsOut; try { cmdConsOut = Utils.execCmd(command); - LOG.debug(cmdConsOut); + LOG.debug(cmdConsOut.toString()); } catch (Exception e) { cmdConsOut = new CmdConsOut(); cmdConsOut.cmd = command; @@ -1131,7 +1132,7 @@ private void queryMemoryUsage() throws IOException, SQLException { } LOG.debug("Result set data types:"); - LOG.debug(Utils.getTypesInStrings(types)); + LOG.debug(Utils.getTypesInStrings(types).toString()); if (resultSet != null) { while (resultSet.next()) { diff --git a/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java b/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java index 57aedfba..62951ea2 100755 --- a/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java +++ b/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java @@ -42,7 +42,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.Lists; import org.apache.drill.test.framework.TestCaseModeler.TestMatrix; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Verification of drill tests by comparing actual query output with expected @@ -50,7 +51,7 @@ * */ public class TestVerifier { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private static final int MAX_MISMATCH_SIZE = 10; public TestStatus testStatus = TestStatus.PENDING; private int mapSize = 0; diff --git a/framework/src/main/java/org/apache/drill/test/framework/Utils.java b/framework/src/main/java/org/apache/drill/test/framework/Utils.java index f01c6aa6..7fbfb6ea 100755 --- a/framework/src/main/java/org/apache/drill/test/framework/Utils.java +++ b/framework/src/main/java/org/apache/drill/test/framework/Utils.java @@ -72,7 +72,8 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; @@ -86,7 +87,7 @@ * */ public class Utils { - private static final Logger LOG = Logger.getLogger("DrillTestLogger"); + private static final Logger LOG = LoggerFactory.getLogger("DrillTestLogger"); private static final Map sqlTypes; private static final Map sqlNullabilities; private static HttpClient client; @@ -573,7 +574,7 @@ public static String getSqlResult(ResultSet resultSet) throws SQLException { } LOG.debug("Result set data types:"); - LOG.debug(Utils.getTypesInStrings(types)); + LOG.debug(Utils.getTypesInStrings(types).toString()); stringBuffer.append(new ColumnList(types, columnLabels).toString()).append("\n"); while (resultSet.next()) { diff --git a/framework/src/test/java/org/apache/drill/test/framework/DrillTestFrameworkUnitTests.java b/framework/src/test/java/org/apache/drill/test/framework/DrillTestFrameworkUnitTests.java index 9ff2656f..90a190d4 100644 --- a/framework/src/test/java/org/apache/drill/test/framework/DrillTestFrameworkUnitTests.java +++ b/framework/src/test/java/org/apache/drill/test/framework/DrillTestFrameworkUnitTests.java @@ -4,7 +4,8 @@ import com.typesafe.config.ConfigFactory; import org.apache.drill.exec.server.rest.profile.CoreOperatorType; import org.apache.drill.test.framework.common.DrillJavaTestBase; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -26,7 +27,7 @@ @Test(groups = UNIT_GROUP) public class DrillTestFrameworkUnitTests extends DrillJavaTestBase { - private static final Logger LOG = Logger.getLogger(DrillTestFrameworkUnitTests.class); + private static final Logger LOG = LoggerFactory.getLogger(DrillTestFrameworkUnitTests.class); @BeforeTest(alwaysRun = true) @@ -185,7 +186,7 @@ public void testTotalMemoryForQueryProfile() { List operators = profile.getOperatorsFromProfile(); Assert.assertTrue(operators.size() > 0, "Number of operators in the profile should be greater than 0"); - operators.forEach(LOG::info); + operators.forEach(o -> LOG.info(o.name())); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); diff --git a/framework/src/test/java/org/apache/drill/test/framework/common/DrillJavaTestBase.java b/framework/src/test/java/org/apache/drill/test/framework/common/DrillJavaTestBase.java index 3bb7b1b6..8c70f5ca 100644 --- a/framework/src/test/java/org/apache/drill/test/framework/common/DrillJavaTestBase.java +++ b/framework/src/test/java/org/apache/drill/test/framework/common/DrillJavaTestBase.java @@ -4,7 +4,8 @@ import org.apache.drill.test.framework.ConnectionPool; import org.apache.drill.test.framework.Utils; import org.apache.drill.test.framework.ssh.DrillCluster; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterSuite; @@ -20,7 +21,7 @@ import java.util.Properties; public class DrillJavaTestBase { - private static final Logger LOG = Logger.getLogger(DrillJavaTestBase.class); + private static final Logger LOG = LoggerFactory.getLogger(DrillJavaTestBase.class); protected ConnectionPool connectionPool; protected DrillCluster drillCluster; diff --git a/framework/src/test/java/org/apache/drill/test/framework/resourcemanagement/QueueSelectionTests.java b/framework/src/test/java/org/apache/drill/test/framework/resourcemanagement/QueueSelectionTests.java index 169e469b..875405d1 100644 --- a/framework/src/test/java/org/apache/drill/test/framework/resourcemanagement/QueueSelectionTests.java +++ b/framework/src/test/java/org/apache/drill/test/framework/resourcemanagement/QueueSelectionTests.java @@ -4,7 +4,8 @@ import org.apache.drill.test.framework.*; import org.apache.drill.test.framework.common.DrillJavaTestBase; import org.apache.drill.test.framework.common.DrillTestNGDefaults; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.*; @@ -23,7 +24,7 @@ @SuppressWarnings("Duplicates") @Test(groups = FUNCTIONAL_GROUP) public class QueueSelectionTests extends DrillJavaTestBase { - private static final Logger LOG = Logger.getLogger(QueueSelectionTests.class); + private static final Logger LOG = LoggerFactory.getLogger(QueueSelectionTests.class); @BeforeClass(alwaysRun = true, description = "Invoked before all tests in the class") private void setup() throws IOException {