From 3340c0024e9e3f18dbdd8bfa684ac5ee94f33564 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Tue, 5 May 2020 20:03:55 +0800 Subject: [PATCH] HBASE-24314 Some classes still use log4j logger directly (#1637) Signed-off-by: Viraj Jasani Signed-off-by: Jan Hentschel --- .../regionserver/handler/RSProcedureHandler.java | 6 ++++-- .../regionserver/RefreshPeerCallable.java | 5 +++-- .../org/apache/hadoop/hbase/GenericTestUtils.java | 3 +-- .../apache/hadoop/hbase/ipc/TestProtoBufRpc.java | 13 +++++++------ .../hadoop/hbase/ipc/TestRpcServerTraceLogging.java | 11 ++++------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/RSProcedureHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/RSProcedureHandler.java index ddff13f0dd9..572e2388b02 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/RSProcedureHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/RSProcedureHandler.java @@ -20,8 +20,9 @@ package org.apache.hadoop.hbase.regionserver.handler; import org.apache.hadoop.hbase.executor.EventHandler; import org.apache.hadoop.hbase.procedure2.RSProcedureCallable; import org.apache.hadoop.hbase.regionserver.HRegionServer; -import org.apache.log4j.Logger; import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A event handler for running procedure. @@ -29,7 +30,8 @@ import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private public class RSProcedureHandler extends EventHandler { - private static final Logger LOG = Logger.getLogger(RSProcedureHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(RSProcedureHandler.class); + private final long procId; private final RSProcedureCallable callable; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RefreshPeerCallable.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RefreshPeerCallable.java index 8fe16bce19e..00991d2272d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RefreshPeerCallable.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RefreshPeerCallable.java @@ -20,8 +20,9 @@ package org.apache.hadoop.hbase.replication.regionserver; import org.apache.hadoop.hbase.executor.EventType; import org.apache.hadoop.hbase.procedure2.RSProcedureCallable; import org.apache.hadoop.hbase.regionserver.HRegionServer; -import org.apache.log4j.Logger; import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException; @@ -34,7 +35,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.R @InterfaceAudience.Private public class RefreshPeerCallable implements RSProcedureCallable { - private static final Logger LOG = Logger.getLogger(RefreshPeerCallable.class); + private static final Logger LOG = LoggerFactory.getLogger(RefreshPeerCallable.class); private HRegionServer rs; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java index 1bde5ae18d0..2fc5dd7ad39 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java @@ -30,13 +30,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; - import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.util.Time; -import org.apache.log4j.Logger; import org.junit.Assert; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import org.slf4j.Logger; import org.apache.hbase.thirdparty.com.google.common.base.Joiner; import org.apache.hbase.thirdparty.com.google.common.base.Supplier; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestProtoBufRpc.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestProtoBufRpc.java index 9e53b923b54..941d921481d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestProtoBufRpc.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestProtoBufRpc.java @@ -21,6 +21,7 @@ import static org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.SERVICE; import static org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.newBlockingStub; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; + import java.io.IOException; import java.net.InetSocketAddress; import java.util.Arrays; @@ -31,8 +32,6 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.testclassification.RPCTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -42,7 +41,9 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; + import org.apache.hbase.thirdparty.com.google.common.collect.Lists; + import org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos; import org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto; import org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto; @@ -81,10 +82,10 @@ public class TestProtoBufRpc { this.conf = HBaseConfiguration.create(); this.conf.set(RpcServerFactory.CUSTOM_RPC_SERVER_IMPL_CONF_KEY, rpcServerImpl); - Logger log = Logger.getLogger("org.apache.hadoop.ipc.HBaseServer"); - log.setLevel(Level.DEBUG); - log = Logger.getLogger("org.apache.hadoop.ipc.HBaseServer.trace"); - log.setLevel(Level.TRACE); + org.apache.log4j.Logger.getLogger("org.apache.hadoop.ipc.HBaseServer") + .setLevel(org.apache.log4j.Level.ERROR); + org.apache.log4j.Logger.getLogger("org.apache.hadoop.ipc.HBaseServer.trace") + .setLevel(org.apache.log4j.Level.TRACE); // Create server side implementation // Get RPC server for server side implementation this.server = RpcServerFactory.createRpcServer(null, "testrpc", diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcServerTraceLogging.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcServerTraceLogging.java index e95c88ce4f5..2d66106a3d2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcServerTraceLogging.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcServerTraceLogging.java @@ -25,15 +25,12 @@ import static org.junit.Assert.assertTrue; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.Mockito; - @Category(SmallTests.class) public class TestRpcServerTraceLogging { @@ -41,7 +38,7 @@ public class TestRpcServerTraceLogging { public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule .forClass(TestRpcServerTraceLogging.class); - static Logger rpcServerLog = Logger.getLogger(RpcServer.class); + static org.apache.log4j.Logger rpcServerLog = org.apache.log4j.Logger.getLogger(RpcServer.class); static final String TRACE_LOG_MSG = "This is dummy message for testing:: region { type: REGION_NAME value: \"hbase:meta,,1\" }" @@ -65,7 +62,7 @@ public class TestRpcServerTraceLogging { @Test public void testLoggingWithTraceOff() { conf.setInt("hbase.ipc.trace.log.max.length", 250); - rpcServerLog.setLevel(Level.DEBUG); + rpcServerLog.setLevel(org.apache.log4j.Level.DEBUG); String truncatedString = mockRpcServer.truncateTraceLog(TRACE_LOG_MSG); assertEquals(150 + RpcServer.KEY_WORD_TRUNCATED.length(), truncatedString.length()); @@ -75,7 +72,7 @@ public class TestRpcServerTraceLogging { @Test public void testLoggingWithTraceOn() { conf.setInt("hbase.ipc.trace.log.max.length", 250); - rpcServerLog.setLevel(Level.TRACE); + rpcServerLog.setLevel(org.apache.log4j.Level.TRACE); String truncatedString = mockRpcServer.truncateTraceLog(TRACE_LOG_MSG); assertEquals(250 + RpcServer.KEY_WORD_TRUNCATED.length(), truncatedString.length()); @@ -85,7 +82,7 @@ public class TestRpcServerTraceLogging { @Test public void testLoggingWithTraceOnLargeMax() { conf.setInt("hbase.ipc.trace.log.max.length", 2000); - rpcServerLog.setLevel(Level.TRACE); + rpcServerLog.setLevel(org.apache.log4j.Level.TRACE); String truncatedString = mockRpcServer.truncateTraceLog(TRACE_LOG_MSG); assertEquals(TRACE_LOG_LENGTH, truncatedString.length());