HBASE-24314 Some classes still use log4j logger directly (#1637)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
This commit is contained in:
Duo Zhang 2020-05-05 20:03:55 +08:00
parent 5e5b13cb51
commit 64bfc99f05
5 changed files with 20 additions and 19 deletions

View File

@ -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;

View File

@ -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,8 @@ 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;
private String peerId;

View File

@ -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;

View File

@ -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",

View File

@ -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());