kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From granthe...@apache.org
Subject [kudu] 01/02: [java] Upgrade to log4j 2
Date Fri, 17 May 2019 14:27:40 GMT
This is an automated email from the ASF dual-hosted git repository.

granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 0114ce1d0ebbec41eef971be341432a0f8f28a76
Author: Grant Henke <granthenke@apache.org>
AuthorDate: Fri May 10 11:51:25 2019 -0500

    [java] Upgrade to log4j 2
    
    This patch upgrades from log4j 1.2.17 to 2.11.2 and
    includes any neccessary changes to support the
    upgrade.
    
    Log4j 2.x has been out for 5 years now and log4j1.x has
    been marked as EOL as of August 2015.
    
    The changes required to support Log4j 2.x are test only
    because we use Slf4j to abstract away our concrete
    logger implementation and allow users to use any
    logging implementaton they like.
    
    Change-Id: Ic4e14a3a25c36d5f47d07f06c1c0e68dad42bc66
    Reviewed-on: http://gerrit.cloudera.org:8080/13304
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <adar@cloudera.com>
---
 java/gradle/dependencies.gradle                    |  6 +-
 java/kudu-backup-tools/build.gradle                |  2 +-
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-backup/build.gradle                      |  2 +-
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-client-tools/build.gradle                |  2 +-
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-client/build.gradle                      |  2 +-
 .../{log4j.properties => log4j2.properties}        | 19 ++++--
 java/kudu-flume-sink/build.gradle                  |  2 +
 ...RegexpKuduOperationsProducerParseErrorTest.java |  7 +-
 .../src/test/resources/log4j.properties            | 23 -------
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-hive/build.gradle                        |  2 +-
 java/kudu-hive/src/test/resources/log4j.properties | 23 -------
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-mapreduce/build.gradle                   |  2 +-
 .../src/test/resources/log4j.properties            | 23 -------
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-spark-tools/build.gradle                 |  2 +-
 .../src/test/resources/log4j.properties            | 23 -------
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-spark/build.gradle                       |  2 +
 .../kudu-spark/src/test/resources/log4j.properties | 23 -------
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 java/kudu-test-utils/build.gradle                  |  2 +-
 .../org/apache/kudu/test/CapturingLogAppender.java | 41 ++++++------
 .../kudu/test/CapturingToFileLogAppender.java      | 77 +++++++++++-----------
 .../src/test/resources/log4j.properties            | 23 -------
 .../src/test/resources/log4j2.properties}          | 19 ++++--
 30 files changed, 219 insertions(+), 260 deletions(-)

diff --git a/java/gradle/dependencies.gradle b/java/gradle/dependencies.gradle
index 5b945cc..93d01b5 100755
--- a/java/gradle/dependencies.gradle
+++ b/java/gradle/dependencies.gradle
@@ -44,7 +44,7 @@ versions += [
     jetty          : "9.4.15.v20190215",
     jsr305         : "3.0.2",
     junit          : "4.12",
-    log4j          : "1.2.17",
+    log4j          : "2.11.2",
     mockito        : "2.25.1",
     murmur         : "1.0.0",
     netty          : "3.10.6.Final",
@@ -103,7 +103,8 @@ libs += [
     jettyServlet         : "org.eclipse.jetty:jetty-servlet:$versions.jetty",
     jsr305               : "com.google.code.findbugs:jsr305:$versions.jsr305",
     junit                : "junit:junit:$versions.junit",
-    log4j                : "log4j:log4j:$versions.log4j",
+    log4j                : "org.apache.logging.log4j:log4j-1.2-api:$versions.log4j",
+    log4jSlf4jImpl       : "org.apache.logging.log4j:log4j-slf4j-impl:$versions.log4j",
     mockitoCore          : "org.mockito:mockito-core:$versions.mockito",
     murmur               : "com.sangupta:murmur:$versions.murmur",
     netty                : "io.netty:netty:$versions.netty",
@@ -117,7 +118,6 @@ libs += [
     scalatest            : "org.scalatest:scalatest_$versions.scalaBase:$versions.scalatest",
     scopt                : "com.github.scopt:scopt_$versions.scalaBase:$versions.scopt",
     slf4jApi             : "org.slf4j:slf4j-api:$versions.slf4j",
-    slf4jLog4j12         : "org.slf4j:slf4j-log4j12:$versions.slf4j",
     sparkAvro            : "org.apache.spark:spark-avro_$versions.scalaBase:$versions.spark",
     sparkCore            : "org.apache.spark:spark-core_$versions.scalaBase:$versions.spark",
     sparkSql             : "org.apache.spark:spark-sql_$versions.scalaBase:$versions.spark",
diff --git a/java/kudu-backup-tools/build.gradle b/java/kudu-backup-tools/build.gradle
index 850060c..cb2a744 100644
--- a/java/kudu-backup-tools/build.gradle
+++ b/java/kudu-backup-tools/build.gradle
@@ -44,8 +44,8 @@ dependencies {
   testCompile project(path: ":kudu-test-utils", configuration: "shadow")
   testCompile libs.junit
   testCompile libs.log4j
+  testCompile libs.log4jSlf4jImpl
   testCompile libs.scalatest
-  testCompile libs.slf4jLog4j12
 }
 
 // Add protobuf files to the proto source set.
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-backup-tools/src/test/resources/log4j2.properties
similarity index 66%
copy from java/kudu-backup/src/test/resources/log4j.properties
copy to java/kudu-backup-tools/src/test/resources/log4j2.properties
index 129752c..25d2bf7 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-backup-tools/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
\ No newline at end of file
diff --git a/java/kudu-backup/build.gradle b/java/kudu-backup/build.gradle
index 514c29d..f303e52 100644
--- a/java/kudu-backup/build.gradle
+++ b/java/kudu-backup/build.gradle
@@ -43,8 +43,8 @@ dependencies {
   testCompile project(path: ":kudu-spark", configuration: "test")
   testCompile libs.junit
   testCompile libs.log4j
+  testCompile libs.log4jSlf4jImpl
   testCompile libs.scalatest
-  testCompile libs.slf4jLog4j12
 }
 
 // Adjust the artifact name to match the maven build.
diff --git a/java/kudu-client-tools/src/test/resources/log4j.properties b/java/kudu-backup/src/test/resources/log4j2.properties
similarity index 66%
rename from java/kudu-client-tools/src/test/resources/log4j.properties
rename to java/kudu-backup/src/test/resources/log4j2.properties
index 129752c..25d2bf7 100644
--- a/java/kudu-client-tools/src/test/resources/log4j.properties
+++ b/java/kudu-backup/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
\ No newline at end of file
diff --git a/java/kudu-client-tools/build.gradle b/java/kudu-client-tools/build.gradle
index 01ed399..4a6c59b 100644
--- a/java/kudu-client-tools/build.gradle
+++ b/java/kudu-client-tools/build.gradle
@@ -33,5 +33,5 @@ dependencies {
   testCompile libs.commonsIo
   testCompile libs.junit
   testCompile libs.log4j
-  testCompile libs.slf4jLog4j12
+  testCompile libs.log4jSlf4jImpl
 }
diff --git a/java/kudu-backup-tools/src/test/resources/log4j.properties b/java/kudu-client-tools/src/test/resources/log4j2.properties
similarity index 66%
rename from java/kudu-backup-tools/src/test/resources/log4j.properties
rename to java/kudu-client-tools/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup-tools/src/test/resources/log4j.properties
+++ b/java/kudu-client-tools/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-client/build.gradle b/java/kudu-client/build.gradle
index ef20ddc..e42b4eb 100644
--- a/java/kudu-client/build.gradle
+++ b/java/kudu-client/build.gradle
@@ -45,8 +45,8 @@ dependencies {
   testCompile libs.hadoopMRClientCore
   testCompile libs.junit
   testCompile libs.log4j
+  testCompile libs.log4jSlf4jImpl
   testCompile libs.mockitoCore
-  testCompile libs.slf4jLog4j12
 }
 
 // Add protobuf files to the proto source set.
diff --git a/java/kudu-client/src/test/resources/log4j.properties b/java/kudu-client/src/test/resources/log4j2.properties
similarity index 66%
rename from java/kudu-client/src/test/resources/log4j.properties
rename to java/kudu-client/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-client/src/test/resources/log4j.properties
+++ b/java/kudu-client/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-flume-sink/build.gradle b/java/kudu-flume-sink/build.gradle
index 9e569fd..cd61cd1 100644
--- a/java/kudu-flume-sink/build.gradle
+++ b/java/kudu-flume-sink/build.gradle
@@ -33,6 +33,8 @@ dependencies {
 
   testCompile project(path: ":kudu-test-utils", configuration: "shadow")
   testCompile libs.junit
+  testCompile libs.log4j
+  testCompile libs.log4jSlf4jImpl
 }
 
 // Configure the Avro plugin to compile the schemas in the
diff --git a/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
b/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
index c367f77..37e33c2 100644
--- a/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
+++ b/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
@@ -28,6 +28,7 @@ import static org.apache.kudu.flume.sink.RegexpKuduOperationsProducer.WARN_UNMAT
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.Closeable;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 
@@ -262,9 +263,9 @@ public class RegexpKuduOperationsProducerParseErrorTest {
   private String processEvent(Context additionalContext, String eventBody) throws Exception
{
     CapturingLogAppender appender = new CapturingLogAppender();
     RegexpKuduOperationsProducer producer = getProducer(additionalContext);
-    appender.attach();
-    producer.getOperations(EventBuilder.withBody(eventBody.getBytes(Charset.forName("UTF-8"))));
-
+    try (Closeable c = appender.attach()) {
+      producer.getOperations(EventBuilder.withBody(eventBody.getBytes(Charset.forName("UTF-8"))));
+    }
     return appender.getAppendedText();
   }
 
diff --git a/java/kudu-flume-sink/src/test/resources/log4j.properties b/java/kudu-flume-sink/src/test/resources/log4j.properties
deleted file mode 100644
index 129752c..0000000
--- a/java/kudu-flume-sink/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
-
-log4j.logger.org.apache.kudu = DEBUG
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-flume-sink/src/test/resources/log4j2.properties
similarity index 66%
copy from java/kudu-backup/src/test/resources/log4j.properties
copy to java/kudu-flume-sink/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-flume-sink/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-hive/build.gradle b/java/kudu-hive/build.gradle
index 31ce577..53d2700 100644
--- a/java/kudu-hive/build.gradle
+++ b/java/kudu-hive/build.gradle
@@ -30,7 +30,7 @@ dependencies {
   testCompile libs.hiveMetastoreTest
   testCompile libs.junit
   testCompile libs.log4j
-  testCompile libs.slf4jLog4j12
+  testCompile libs.log4jSlf4jImpl
 }
 
 // kudu-hive has no public Javadoc.
diff --git a/java/kudu-hive/src/test/resources/log4j.properties b/java/kudu-hive/src/test/resources/log4j.properties
deleted file mode 100644
index 129752c..0000000
--- a/java/kudu-hive/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
-
-log4j.logger.org.apache.kudu = DEBUG
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-hive/src/test/resources/log4j2.properties
similarity index 66%
copy from java/kudu-backup/src/test/resources/log4j.properties
copy to java/kudu-hive/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-hive/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-mapreduce/build.gradle b/java/kudu-mapreduce/build.gradle
index 39ef80e..f53f156 100644
--- a/java/kudu-mapreduce/build.gradle
+++ b/java/kudu-mapreduce/build.gradle
@@ -34,5 +34,5 @@ dependencies {
   testCompile libs.commonsIo
   testCompile libs.junit
   testCompile libs.log4j
-  testCompile libs.slf4jLog4j12
+  testCompile libs.log4jSlf4jImpl
 }
\ No newline at end of file
diff --git a/java/kudu-mapreduce/src/test/resources/log4j.properties b/java/kudu-mapreduce/src/test/resources/log4j.properties
deleted file mode 100644
index 129752c..0000000
--- a/java/kudu-mapreduce/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
-
-log4j.logger.org.apache.kudu = DEBUG
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-mapreduce/src/test/resources/log4j2.properties
similarity index 66%
copy from java/kudu-backup/src/test/resources/log4j.properties
copy to java/kudu-mapreduce/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-mapreduce/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-spark-tools/build.gradle b/java/kudu-spark-tools/build.gradle
index 58dcb3a..57090a0 100644
--- a/java/kudu-spark-tools/build.gradle
+++ b/java/kudu-spark-tools/build.gradle
@@ -39,8 +39,8 @@ dependencies {
   testCompile project(path: ":kudu-spark", configuration: "test")
   testCompile libs.junit
   testCompile libs.log4j
+  testCompile libs.log4jSlf4jImpl
   testCompile libs.scalatest
-  testCompile libs.slf4jLog4j12
 }
 
 // Adjust the artifact name to match the maven build.
diff --git a/java/kudu-spark-tools/src/test/resources/log4j.properties b/java/kudu-spark-tools/src/test/resources/log4j.properties
deleted file mode 100644
index 129752c..0000000
--- a/java/kudu-spark-tools/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
-
-log4j.logger.org.apache.kudu = DEBUG
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-spark-tools/src/test/resources/log4j2.properties
similarity index 66%
copy from java/kudu-backup/src/test/resources/log4j.properties
copy to java/kudu-spark-tools/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-spark-tools/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-spark/build.gradle b/java/kudu-spark/build.gradle
index 25d208b..6c8e833 100644
--- a/java/kudu-spark/build.gradle
+++ b/java/kudu-spark/build.gradle
@@ -33,6 +33,8 @@ dependencies {
   testCompile project(path: ":kudu-test-utils", configuration: "shadow")
   testCompile libs.junit
   testCompile libs.scalatest
+  testCompile libs.log4j
+  testCompile libs.log4jSlf4jImpl
 }
 
 // Adjust the artifact name to include the spark and scala base versions.
diff --git a/java/kudu-spark/src/test/resources/log4j.properties b/java/kudu-spark/src/test/resources/log4j.properties
deleted file mode 100644
index 129752c..0000000
--- a/java/kudu-spark/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
-
-log4j.logger.org.apache.kudu = DEBUG
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-spark/src/test/resources/log4j2.properties
similarity index 66%
copy from java/kudu-backup/src/test/resources/log4j.properties
copy to java/kudu-spark/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-spark/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug
diff --git a/java/kudu-test-utils/build.gradle b/java/kudu-test-utils/build.gradle
index fbd8323..3e03012 100644
--- a/java/kudu-test-utils/build.gradle
+++ b/java/kudu-test-utils/build.gradle
@@ -37,7 +37,7 @@ dependencies {
 
   // Needed for CapturingLogAppender. Optional otherwise.
   optional libs.log4j
-  optional libs.slf4jLog4j12
+  optional libs.log4jSlf4jImpl
 
   optional libs.jsr305
   optional libs.yetusAnnotations
diff --git a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingLogAppender.java
b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingLogAppender.java
index 056ef80..4bf1d88 100644
--- a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingLogAppender.java
+++ b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingLogAppender.java
@@ -20,11 +20,11 @@ import java.io.Closeable;
 import java.io.IOException;
 
 import com.google.common.base.Throwables;
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Layout;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
@@ -35,26 +35,25 @@ import org.apache.yetus.audience.InterfaceStability;
  */
 @InterfaceAudience.Private
 @InterfaceStability.Unstable
-public class CapturingLogAppender extends AppenderSkeleton {
-  private static final Layout LAYOUT = new SimpleLayout();
+public class CapturingLogAppender extends AbstractAppender {
+  // This is the standard layout used in Kudu tests.
+  private static final PatternLayout LAYOUT = PatternLayout.newBuilder()
+      .withPattern("%d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n")
+      .build();
 
   private StringBuilder appended = new StringBuilder();
 
-  @Override
-  public void close() {
-  }
-
-  @Override
-  public boolean requiresLayout() {
-    return false;
+  public CapturingLogAppender() {
+    super("CapturingLogAppender", /* filter */ null, LAYOUT,
+        /* ignoreExceptions */ true, Property.EMPTY_ARRAY);
   }
 
   @Override
-  protected void append(LoggingEvent event) {
-    appended.append(LAYOUT.format(event));
-    if (event.getThrowableInformation() != null) {
-      appended.append(Throwables.getStackTraceAsString(
-          event.getThrowableInformation().getThrowable())).append("\n");
+  public void append(LogEvent event) {
+    appended.append(getLayout().toSerializable(event));
+    if (event.getThrown() != null) {
+      appended.append(Throwables.getStackTraceAsString(event.getThrown()));
+      appended.append("\n");
     }
   }
 
@@ -75,11 +74,11 @@ public class CapturingLogAppender extends AppenderSkeleton {
    * </code>
    */
   public Closeable attach() {
-    Logger.getRootLogger().addAppender(this);
+    LoggerContext.getContext(false).getRootLogger().addAppender(this);
     return new Closeable() {
       @Override
       public void close() throws IOException {
-        Logger.getRootLogger().removeAppender(CapturingLogAppender.this);
+        LoggerContext.getContext(false).getRootLogger().removeAppender(CapturingLogAppender.this);
       }
     };
   }
diff --git a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingToFileLogAppender.java
b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingToFileLogAppender.java
index 6eea54a..c0009a8 100644
--- a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingToFileLogAppender.java
+++ b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/CapturingToFileLogAppender.java
@@ -27,12 +27,11 @@ import java.io.Writer;
 import java.util.zip.GZIPOutputStream;
 
 import com.google.common.base.Throwables;
-import org.apache.commons.io.IOUtils;
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Layout;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
@@ -52,10 +51,11 @@ import static java.nio.charset.StandardCharsets.UTF_8;
  */
 @InterfaceAudience.Private
 @InterfaceStability.Unstable
-public class CapturingToFileLogAppender extends AppenderSkeleton implements AutoCloseable
{
+public class CapturingToFileLogAppender extends AbstractAppender implements AutoCloseable
{
   // This is the standard layout used in Kudu tests.
-  private static final Layout LAYOUT = new PatternLayout(
-      "%d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n");
+  private static final PatternLayout LAYOUT = PatternLayout.newBuilder()
+      .withPattern("%d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n")
+      .build();
 
   private File outputFile;
   private Writer outputFileWriter;
@@ -69,33 +69,41 @@ public class CapturingToFileLogAppender extends AppenderSkeleton implements
Auto
    * @param useGzip whether to gzip-compress messages when appended
    */
   public CapturingToFileLogAppender(boolean useGzip) throws IOException {
+    super("CapturingToFileLogAppender", /* filter */ null, LAYOUT,
+        /* ignoreExceptions */ true, Property.EMPTY_ARRAY);
     outputFile = File.createTempFile("captured_output", ".txt.gz");
-    try {
-      OutputStream os = new FileOutputStream(outputFile.getPath());
-      try {
-        if (useGzip) {
-          os = new GZIPOutputStream(os);
-        }
-
-        // As per the recommendation in OutputStreamWriter's Javadoc, we wrap in a
-        // BufferedWriter to buffer up character conversions.
-        outputFileWriter = new BufferedWriter(new OutputStreamWriter(os, UTF_8));
-      } catch (Throwable t) {
-        IOUtils.closeQuietly(os);
-        throw t;
-      }
+    try (OutputStream os = createOutputStream(useGzip)) {
+      // As per the recommendation in OutputStreamWriter's Javadoc, we wrap in a
+      // BufferedWriter to buffer up character conversions.
+      outputFileWriter = new BufferedWriter(new OutputStreamWriter(os, UTF_8));
     } catch (Throwable t) {
       outputFile.delete();
       throw t;
     }
   }
 
+  private OutputStream createOutputStream(boolean useGzip) throws IOException {
+    OutputStream os = new FileOutputStream(outputFile.getPath());
+    if (useGzip) {
+      try {
+        os = new GZIPOutputStream(os);
+      } catch (IOException ex) {
+        os.close();
+        throw ex;
+      }
+    }
+    return os;
+  }
+
   @Override
   public void close() {
     // Just do the cleanup; we don't care about exceptions/logging.
-
     if (outputFileWriter != null) {
-      IOUtils.closeQuietly(outputFileWriter);
+      try {
+        outputFileWriter.close();
+      } catch (final IOException ioe) {
+        // ignored
+      }
       outputFileWriter = null;
     }
     if (outputFile != null) {
@@ -105,18 +113,12 @@ public class CapturingToFileLogAppender extends AppenderSkeleton implements
Auto
   }
 
   @Override
-  public boolean requiresLayout() {
-    return false;
-  }
-
-  @Override
-  protected void append(LoggingEvent event) {
+  public void append(LogEvent event) {
     assert outputFileWriter != null;
     try {
-      outputFileWriter.write(LAYOUT.format(event));
-      if (event.getThrowableInformation() != null) {
-        outputFileWriter.write(Throwables.getStackTraceAsString(
-            event.getThrowableInformation().getThrowable()));
+      outputFileWriter.write(LAYOUT.toSerializable(event));
+      if (event.getThrown() != null) {
+        outputFileWriter.write(Throwables.getStackTraceAsString(event.getThrown()));
         outputFileWriter.write("\n");
       }
     } catch (IOException e) {
@@ -166,11 +168,12 @@ public class CapturingToFileLogAppender extends AppenderSkeleton implements
Auto
    * </code>
    */
   public Closeable attach() {
-    Logger.getRootLogger().addAppender(this);
+    LoggerContext.getContext(false).getRootLogger().addAppender(this);
     return new Closeable() {
       @Override
       public void close() throws IOException {
-        Logger.getRootLogger().removeAppender(CapturingToFileLogAppender.this);
+        LoggerContext.getContext(false).getRootLogger()
+            .removeAppender(CapturingToFileLogAppender.this);
       }
     };
   }
diff --git a/java/kudu-test-utils/src/test/resources/log4j.properties b/java/kudu-test-utils/src/test/resources/log4j.properties
deleted file mode 100644
index 129752c..0000000
--- a/java/kudu-test-utils/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
-
-log4j.logger.org.apache.kudu = DEBUG
diff --git a/java/kudu-backup/src/test/resources/log4j.properties b/java/kudu-test-utils/src/test/resources/log4j2.properties
similarity index 66%
rename from java/kudu-backup/src/test/resources/log4j.properties
rename to java/kudu-test-utils/src/test/resources/log4j2.properties
index 129752c..4b67b5e 100644
--- a/java/kudu-backup/src/test/resources/log4j.properties
+++ b/java/kudu-test-utils/src/test/resources/log4j2.properties
@@ -15,9 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 
-log4j.rootLogger = INFO, out
-log4j.appender.out = org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout = org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+status = error
+name = PropertiesConfig
+appenders = console
 
-log4j.logger.org.apache.kudu = DEBUG
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%p - %t] (%F:%L) %m%n
+
+rootLogger.level = debug
+rootLogger.appenderRefs = stdout
+rootLogger.appenderRef.stdout.ref = STDOUT
+
+logger.kudu.name = org.apache.kudu
+logger.kudu.level = debug


Mime
View raw message