Skip to content

Commit

Permalink
HBASE-24314 Some classes still use log4j logger directly (#1637)
Browse files Browse the repository at this point in the history
Signed-off-by: Viraj Jasani <[email protected]>
Signed-off-by: Jan Hentschel <[email protected]>
  • Loading branch information
Apache9 authored May 5, 2020
1 parent d29bdd3 commit 3340c00
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
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.
*/
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
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;

Expand All @@ -34,7 +35,7 @@
@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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand All @@ -31,8 +32,6 @@
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;
Expand All @@ -42,7 +41,9 @@
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;
Expand Down Expand Up @@ -81,10 +82,10 @@ public void setUp() throws IOException { // Setup server for both protocols
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@
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 {

@ClassRule
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\" }"
Expand All @@ -65,7 +62,7 @@ public static void setUp() {
@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());
Expand All @@ -75,7 +72,7 @@ public void testLoggingWithTraceOff() {
@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());
Expand All @@ -85,7 +82,7 @@ public void testLoggingWithTraceOn() {
@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());
Expand Down

0 comments on commit 3340c00

Please sign in to comment.