From a5aa8d208e00fbe169873a894d40107195dbfcf3 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Wed, 13 May 2020 17:59:21 +0800 Subject: [PATCH] =?UTF-8?q?HBASE-24309=20Avoid=20introducing=20log4j=20and?= =?UTF-8?q?=20slf4j-log4j=20dependencies=20for=20=E2=80=A6=20(#1697)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: stack --- hbase-archetypes/hbase-client-project/pom.xml | 16 +- .../hbase-shaded-client-project/pom.xml | 13 +- hbase-assembly/pom.xml | 21 ++ hbase-assembly/src/main/assembly/client.xml | 42 ++-- .../src/main/assembly/hadoop-three-compat.xml | 4 +- .../src/main/assembly/hadoop-two-compat.xml | 2 + hbase-asyncfs/pom.xml | 26 +++ hbase-client/pom.xml | 21 ++ .../src/test/resources/log4j.properties | 68 ------- hbase-common/pom.xml | 28 ++- .../hadoop/hbase/logging/TestLog4jUtils.java | 71 +++++++ .../src/test/resources/log4j.properties | 68 ------- hbase-endpoint/pom.xml | 26 +++ hbase-examples/pom.xml | 30 +++ .../src/test/resources/log4j.properties | 69 ------- hbase-hadoop-compat/pom.xml | 27 ++- hbase-hadoop2-compat/pom.xml | 29 ++- hbase-hbtop/pom.xml | 26 +++ hbase-http/pom.xml | 20 +- .../hadoop/hbase/http/log/LogLevel.java | 54 ++--- .../hadoop/hbase/util}/LogMonitoring.java | 45 +---- .../src/test/resources/log4j.properties | 68 ------- hbase-it/pom.xml | 23 ++- hbase-logging/pom.xml | 92 +++++++++ .../hadoop/hbase/AsyncConsoleAppender.java | 11 +- .../hbase/logging/InternalLog4jUtils.java | 70 +++++++ .../hadoop/hbase/logging/Log4jUtils.java | 121 +++++++++++ .../src/test/resources/log4j.properties | 0 hbase-mapreduce/pom.xml | 30 ++- .../MapreduceDependencyClasspathTool.java | 10 +- .../src/test/resources/log4j.properties | 68 ------- hbase-metrics-api/pom.xml | 26 +++ hbase-metrics/pom.xml | 26 +++ hbase-procedure/pom.xml | 26 +++ .../src/test/resources/log4j.properties | 68 ------- hbase-replication/pom.xml | 26 +++ hbase-rest/pom.xml | 26 +++ .../src/test/resources/log4j.properties | 69 ------- hbase-rsgroup/pom.xml | 29 ++- .../src/test/resources/log4j.properties | 68 ------- hbase-server/pom.xml | 43 ++-- .../hbase/master/MasterDumpServlet.java | 2 +- .../hbase/regionserver/RSDumpServlet.java | 7 +- .../hadoop/hbase/HBaseTestingUtility.java | 23 +-- .../src/test/resources/log4j.properties | 72 ------- hbase-shaded/pom.xml | 5 +- hbase-shell/pom.xml | 26 +++ .../src/test/resources/log4j.properties | 68 ------- hbase-testing-util/pom.xml | 23 +++ hbase-thrift/pom.xml | 26 +++ hbase-zookeeper/pom.xml | 30 ++- .../src/test/resources/log4j.properties | 68 ------- pom.xml | 191 +++++++++++++++--- 53 files changed, 1191 insertions(+), 956 deletions(-) delete mode 100644 hbase-client/src/test/resources/log4j.properties create mode 100644 hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java delete mode 100644 hbase-common/src/test/resources/log4j.properties delete mode 100644 hbase-examples/src/test/resources/log4j.properties rename {hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring => hbase-http/src/main/java/org/apache/hadoop/hbase/util}/LogMonitoring.java (65%) delete mode 100644 hbase-http/src/test/resources/log4j.properties create mode 100644 hbase-logging/pom.xml rename {hbase-common => hbase-logging}/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java (79%) create mode 100644 hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/InternalLog4jUtils.java create mode 100644 hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/Log4jUtils.java rename {hbase-asyncfs => hbase-logging}/src/test/resources/log4j.properties (100%) delete mode 100644 hbase-mapreduce/src/test/resources/log4j.properties delete mode 100644 hbase-procedure/src/test/resources/log4j.properties delete mode 100644 hbase-rest/src/test/resources/log4j.properties delete mode 100644 hbase-rsgroup/src/test/resources/log4j.properties delete mode 100644 hbase-server/src/test/resources/log4j.properties delete mode 100644 hbase-shell/src/test/resources/log4j.properties delete mode 100644 hbase-zookeeper/src/test/resources/log4j.properties diff --git a/hbase-archetypes/hbase-client-project/pom.xml b/hbase-archetypes/hbase-client-project/pom.xml index 4cce0003fe4..2248fe1dad8 100644 --- a/hbase-archetypes/hbase-client-project/pom.xml +++ b/hbase-archetypes/hbase-client-project/pom.xml @@ -43,31 +43,35 @@ org.apache.hbase hbase-testing-util - ${project.version} test org.apache.hbase hbase-common - ${project.version} org.apache.hbase hbase-client - ${project.version} - jar + + + org.slf4j + slf4j-log4j12 + runtime + + + log4j + log4j + runtime org.apache.hbase hbase-server - ${project.version} test-jar test junit junit - ${junit.version} test diff --git a/hbase-archetypes/hbase-shaded-client-project/pom.xml b/hbase-archetypes/hbase-shaded-client-project/pom.xml index fd5bf85ce3b..e056badcb58 100644 --- a/hbase-archetypes/hbase-shaded-client-project/pom.xml +++ b/hbase-archetypes/hbase-shaded-client-project/pom.xml @@ -43,7 +43,6 @@ org.apache.hbase hbase-testing-util - ${project.version} test @@ -59,12 +58,20 @@ org.apache.hbase hbase-shaded-client - ${project.version} + + + org.slf4j + slf4j-log4j12 + runtime + + + log4j + log4j + runtime junit junit - ${junit.version} test diff --git a/hbase-assembly/pom.xml b/hbase-assembly/pom.xml index 0920949f623..5706790a187 100644 --- a/hbase-assembly/pom.xml +++ b/hbase-assembly/pom.xml @@ -318,6 +318,27 @@ jaxws-ri pom + + + org.slf4j + jcl-over-slf4j + + + org.slf4j + jul-to-slf4j + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + diff --git a/hbase-assembly/src/main/assembly/client.xml b/hbase-assembly/src/main/assembly/client.xml index 884ac2a2cbf..bd65cb43f8e 100644 --- a/hbase-assembly/src/main/assembly/client.xml +++ b/hbase-assembly/src/main/assembly/client.xml @@ -1,5 +1,7 @@ - + hbase-${project.version}-client - src/main/assembly/client-components.xml + src/main/assembly/client-components.xml @@ -40,8 +42,8 @@ false lib - - + + com.sun.xml.ws:jaxws-ri @@ -50,20 +52,22 @@ com.sun.jersey:* com.sun.jersey.contribs:* jline:jline - com.github.stephenc.findbugs:findbugs-annotations - commons-logging:commons-logging - log4j:log4j - org.apache.hbase:hbase-shaded-client - org.apache.hbase:hbase-shaded-client-byo-hadoop - org.apache.hbase:hbase-shaded-mapreduce - org.apache.htrace:htrace-core4 - org.apache.htrace:htrace-core - org.apache.yetus:audience-annotations - org.slf4j:slf4j-api - org.slf4j:slf4j-log4j12 + com.github.stephenc.findbugs:findbugs-annotations + commons-logging:commons-logging + log4j:log4j + org.apache.hbase:hbase-shaded-client + org.apache.hbase:hbase-shaded-client-byo-hadoop + org.apache.hbase:hbase-shaded-mapreduce + org.apache.htrace:htrace-core4 + org.apache.htrace:htrace-core + org.apache.yetus:audience-annotations + org.slf4j:slf4j-api + org.slf4j:jcl-over-slf4j + org.slf4j:jul-to-slf4j + org.slf4j:slf4j-log4j12 - - + + @@ -91,7 +95,7 @@ - lib/shaded-clients + lib/shaded-clients org.apache.hbase:hbase-shaded-client org.apache.hbase:hbase-shaded-mapreduce @@ -146,6 +150,8 @@ org.apache.htrace:htrace-core org.apache.yetus:audience-annotations org.slf4j:slf4j-api + org.slf4j:jcl-over-slf4j + org.slf4j:jul-to-slf4j org.slf4j:slf4j-log4j12 diff --git a/hbase-assembly/src/main/assembly/hadoop-three-compat.xml b/hbase-assembly/src/main/assembly/hadoop-three-compat.xml index 9c221f11311..e5422f39e5f 100644 --- a/hbase-assembly/src/main/assembly/hadoop-three-compat.xml +++ b/hbase-assembly/src/main/assembly/hadoop-three-compat.xml @@ -35,7 +35,6 @@ org.apache.hbase:hbase-annotations org.apache.hbase:hbase-asyncfs - org.apache.hbase:hbase-backup org.apache.hbase:hbase-client org.apache.hbase:hbase-common org.apache.hbase:hbase-endpoint @@ -45,6 +44,7 @@ org.apache.hbase:hbase-hadoop2-compat org.apache.hbase:hbase-http org.apache.hbase:hbase-it + org.apache.hbase:hbase-logging org.apache.hbase:hbase-mapreduce org.apache.hbase:hbase-metrics org.apache.hbase:hbase-metrics-api @@ -209,6 +209,8 @@ org.apache.htrace:htrace-core org.apache.yetus:audience-annotations org.slf4j:slf4j-api + org.slf4j:jcl-over-slf4j + org.slf4j:jul-to-slf4j org.slf4j:slf4j-log4j12 diff --git a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml index 5520fbc24b8..750027812e0 100644 --- a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml +++ b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml @@ -37,12 +37,14 @@ org.apache.hbase:hbase-asyncfs org.apache.hbase:hbase-client org.apache.hbase:hbase-common + org.apache.hbase:hbase-endpoint org.apache.hbase:hbase-examples org.apache.hbase:hbase-external-blockcache org.apache.hbase:hbase-hadoop-compat org.apache.hbase:hbase-hadoop2-compat org.apache.hbase:hbase-http org.apache.hbase:hbase-it + org.apache.hbase:hbase-logging org.apache.hbase:hbase-mapreduce org.apache.hbase:hbase-metrics org.apache.hbase:hbase-metrics-api diff --git a/hbase-asyncfs/pom.xml b/hbase-asyncfs/pom.xml index 452088b163e..d37054639b8 100644 --- a/hbase-asyncfs/pom.xml +++ b/hbase-asyncfs/pom.xml @@ -72,6 +72,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -132,6 +138,26 @@ mockito-core test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-client/pom.xml b/hbase-client/pom.xml index 98ea5ec91ae..7f78e9d9fa4 100644 --- a/hbase-client/pom.xml +++ b/hbase-client/pom.xml @@ -66,6 +66,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -150,6 +156,21 @@ org.jruby.joni joni + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + log4j log4j diff --git a/hbase-client/src/test/resources/log4j.properties b/hbase-client/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-client/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml index 9520d07aa6c..5a7e8712ae4 100644 --- a/hbase-common/pom.xml +++ b/hbase-common/pom.xml @@ -30,7 +30,6 @@ hbase-common Apache HBase - Common Common functionality for HBase - @@ -146,6 +145,16 @@ test-jar test + + org.apache.hbase + hbase-logging + + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase.thirdparty hbase-shaded-miscellaneous @@ -207,9 +216,24 @@ test - + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + log4j log4j + test org.apache.kerby diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java new file mode 100644 index 00000000000..89931de7128 --- /dev/null +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java @@ -0,0 +1,71 @@ +/** + * 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. + */ +package org.apache.hadoop.hbase.logging; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.MiscTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * This should be in the hbase-logging module but the {@link HBaseClassTestRule} is in hbase-common + * so we can only put the class in hbase-common module for now... + */ +@Category({ MiscTests.class, SmallTests.class }) +public class TestLog4jUtils { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestLog4jUtils.class); + + @Test + public void test() { + Logger zk = LogManager.getLogger("org.apache.zookeeper"); + Level zkLevel = zk.getEffectiveLevel(); + Logger hbaseZk = LogManager.getLogger("org.apache.hadoop.hbase.zookeeper"); + Level hbaseZkLevel = hbaseZk.getEffectiveLevel(); + Logger client = LogManager.getLogger("org.apache.hadoop.hbase.client"); + Level clientLevel = client.getEffectiveLevel(); + Log4jUtils.disableZkAndClientLoggers(); + assertEquals(Level.OFF, zk.getLevel()); + assertEquals(Level.OFF.toString(), Log4jUtils.getEffectiveLevel(zk.getName())); + assertEquals(Level.OFF, hbaseZk.getLevel()); + assertEquals(Level.OFF.toString(), Log4jUtils.getEffectiveLevel(hbaseZk.getName())); + assertEquals(Level.OFF, client.getLevel()); + assertEquals(Level.OFF.toString(), Log4jUtils.getEffectiveLevel(client.getName())); + // restore the level + zk.setLevel(zkLevel); + hbaseZk.setLevel(hbaseZkLevel); + client.setLevel(clientLevel); + } + + @Test + public void testGetLogFiles() throws IOException { + // we use console appender in tests so the active log files should be empty + assertTrue(Log4jUtils.getActiveLogFiles().isEmpty()); + } +} diff --git a/hbase-common/src/test/resources/log4j.properties b/hbase-common/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-common/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-endpoint/pom.xml b/hbase-endpoint/pom.xml index 3636422e61c..f455baaf0d1 100644 --- a/hbase-endpoint/pom.xml +++ b/hbase-endpoint/pom.xml @@ -93,6 +93,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -211,6 +217,26 @@ mockito-core test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-examples/pom.xml b/hbase-examples/pom.xml index e54ec36350c..571808dc711 100644 --- a/hbase-examples/pom.xml +++ b/hbase-examples/pom.xml @@ -95,6 +95,16 @@ org.apache.hbase hbase-protocol + + org.apache.hbase + hbase-logging + test-jar + test + + + org.apache.hbase + hbase-common + org.apache.hbase hbase-client @@ -208,6 +218,26 @@ test test-jar + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-examples/src/test/resources/log4j.properties b/hbase-examples/src/test/resources/log4j.properties deleted file mode 100644 index 4e5f014bc6c..00000000000 --- a/hbase-examples/src/test/resources/log4j.properties +++ /dev/null @@ -1,69 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE -log4j.logger.org.apache.directory=WARN diff --git a/hbase-hadoop-compat/pom.xml b/hbase-hadoop-compat/pom.xml index 6d2f73a3046..d0456637d9e 100644 --- a/hbase-hadoop-compat/pom.xml +++ b/hbase-hadoop-compat/pom.xml @@ -33,7 +33,6 @@ Interfaces to be implemented in order to smooth over hadoop version differences - @@ -63,6 +62,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -87,6 +92,26 @@ junit test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-hadoop2-compat/pom.xml b/hbase-hadoop2-compat/pom.xml index 15892225271..c1a730a7719 100644 --- a/hbase-hadoop2-compat/pom.xml +++ b/hbase-hadoop2-compat/pom.xml @@ -118,14 +118,12 @@ limitations under the License. org.apache.hbase hbase-hadoop-compat - ${project.version} test-jar test org.apache.hadoop hadoop-mapreduce-client-core - ${hadoop.version} com.google.guava @@ -141,10 +139,15 @@ limitations under the License. + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hadoop hadoop-common - ${hadoop.version} + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -252,15 +258,25 @@ hadoop-minikdc test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + org.slf4j slf4j-log4j12 - provided + test log4j log4j - provided + test diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java index 3ab3957a144..dede1f9d8fd 100644 --- a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java @@ -32,23 +32,20 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.impl.Jdk14Logger; -import org.apache.commons.logging.impl.Log4JLogger; import org.apache.hadoop.HadoopIllegalArgumentException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.hbase.http.HttpServer; +import org.apache.hadoop.hbase.logging.Log4jUtils; import org.apache.hadoop.security.authentication.client.AuthenticatedURL; import org.apache.hadoop.security.authentication.client.KerberosAuthenticator; import org.apache.hadoop.security.ssl.SSLFactory; import org.apache.hadoop.util.ServletUtil; import org.apache.hadoop.util.Tool; -import org.apache.log4j.LogManager; import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceStability; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.Log4jLoggerAdapter; import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; import org.apache.hbase.thirdparty.com.google.common.base.Charsets; @@ -355,16 +352,7 @@ public final class LogLevel { if (level != null) { out.println(MARKER + "Submitted Level: " + level + "
"); } - - if (log instanceof Log4JLogger) { - process(((Log4JLogger)log).getLogger(), level, out); - } else if (log instanceof Jdk14Logger) { - process(((Jdk14Logger)log).getLogger(), level, out); - } else if (log instanceof Log4jLoggerAdapter) { - process(LogManager.getLogger(logName), level, out); - } else { - out.println("Sorry, " + log.getClass() + " not supported.
"); - } + process(log, level, out); } try { @@ -398,35 +386,19 @@ public final class LogLevel { + "Set the specified log level for the specified log name." + "\n" + "\n" + "\n" + "\n" + "\n" + "

\n" + "
\n"; - private static void process(org.apache.log4j.Logger log, String level, PrintWriter out) { - if (level != null) { - if (!level.equals(org.apache.log4j.Level.toLevel(level).toString())) { - out.println(MARKER + "
" + "Bad level : " + level - + "
" + "
"); - } else { - log.setLevel(org.apache.log4j.Level.toLevel(level)); - out.println(MARKER + "
" + "Setting Level to " + level - + " ...
" + "
"); + private static void process(Logger logger, String levelName, PrintWriter out) { + if (levelName != null) { + try { + Log4jUtils.setLogLevel(logger.getName(), levelName); + out.println(MARKER + "
" + "Setting Level to " + + levelName + " ...
" + "
"); + } catch (IllegalArgumentException e) { + out.println(MARKER + "
" + "Bad level : " + levelName + + "
" + "
"); } } - out.println(MARKER - + "Effective level: " + log.getEffectiveLevel() + "
"); - } - - private static void process(java.util.logging.Logger log, String level, - PrintWriter out) { - if (level != null) { - log.setLevel(java.util.logging.Level.parse(level)); - out.println(MARKER + "Setting Level to " + level + " ...
"); - } - - java.util.logging.Level lev; - - while ((lev = log.getLevel()) == null) { - log = log.getParent(); - } - - out.println(MARKER + "Effective level: " + lev + "
"); + out.println(MARKER + "Effective level: " + Log4jUtils.getEffectiveLevel(logger.getName()) + + "
"); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/LogMonitoring.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/util/LogMonitoring.java similarity index 65% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/LogMonitoring.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/util/LogMonitoring.java index 8cede154bb7..2b36c21c616 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/LogMonitoring.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/util/LogMonitoring.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.monitoring; +package org.apache.hadoop.hbase.util; import java.io.BufferedReader; import java.io.File; @@ -25,43 +25,19 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.nio.channels.FileChannel; -import java.util.Enumeration; import java.util.Set; - -import org.apache.yetus.audience.InterfaceAudience; +import org.apache.hadoop.hbase.logging.Log4jUtils; import org.apache.hadoop.io.IOUtils; -import org.apache.log4j.Appender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Logger; - -import org.apache.hbase.thirdparty.com.google.common.collect.Sets; +import org.apache.yetus.audience.InterfaceAudience; /** - * Utility functions for reading the log4j logs that are - * being written by HBase. + * Utility functions for reading the log4j logs that are being written by HBase. */ @InterfaceAudience.Private public abstract class LogMonitoring { - public static Set getActiveLogFiles() throws IOException { - Set ret = Sets.newHashSet(); - Appender a; - @SuppressWarnings("unchecked") - Enumeration e = Logger.getRootLogger().getAllAppenders(); - while (e.hasMoreElements()) { - a = e.nextElement(); - if (a instanceof FileAppender) { - FileAppender fa = (FileAppender) a; - String filename = fa.getFile(); - ret.add(new File(filename)); - } - } - return ret; - } - - public static void dumpTailOfLogs( - PrintWriter out, long tailKb) throws IOException { - Set logs = LogMonitoring.getActiveLogFiles(); + public static void dumpTailOfLogs(PrintWriter out, long tailKb) throws IOException { + Set logs = Log4jUtils.getActiveLogFiles(); for (File f : logs) { out.println("+++++++++++++++++++++++++++++++"); out.println(f.getAbsolutePath()); @@ -76,13 +52,12 @@ public abstract class LogMonitoring { } } - private static void dumpTailOfLog(File f, PrintWriter out, long tailKb) - throws IOException { + private static void dumpTailOfLog(File f, PrintWriter out, long tailKb) throws IOException { FileInputStream fis = new FileInputStream(f); BufferedReader r = null; try { FileChannel channel = fis.getChannel(); - channel.position(Math.max(0, channel.size() - tailKb*1024)); + channel.position(Math.max(0, channel.size() - tailKb * 1024)); r = new BufferedReader(new InputStreamReader(fis)); r.readLine(); // skip the first partial line String line; @@ -90,7 +65,9 @@ public abstract class LogMonitoring { out.println(line); } } finally { - if (r != null) IOUtils.closeStream(r); + if (r != null) { + IOUtils.closeStream(r); + } IOUtils.closeStream(fis); } } diff --git a/hbase-http/src/test/resources/log4j.properties b/hbase-http/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-http/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-it/pom.xml b/hbase-it/pom.xml index c9a6a8d0d13..ecb230a4ce3 100644 --- a/hbase-it/pom.xml +++ b/hbase-it/pom.xml @@ -154,6 +154,12 @@ test-jar test
+ + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -253,9 +259,24 @@ test - + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + log4j log4j + test javax.servlet-api diff --git a/hbase-logging/pom.xml b/hbase-logging/pom.xml new file mode 100644 index 00000000000..70cb659c08b --- /dev/null +++ b/hbase-logging/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + hbase-build-configuration + org.apache.hbase + 2.3.0-SNAPSHOT + ../hbase-build-configuration + + + hbase-logging + Apache HBase - Logging + Logging Support for HBase + + + + + src/test/resources + + log4j.properties + + + + + + + maven-assembly-plugin + + true + + + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code + warbucks-maven-plugin + + + + + + + org.apache.hbase + hbase-annotations + test-jar + test + + + org.slf4j + slf4j-api + + + junit + junit + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + provided + + + diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java b/hbase-logging/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java similarity index 79% rename from hbase-common/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java rename to hbase-logging/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java index 22f5ec2a0d4..939b453c8d4 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java +++ b/hbase-logging/src/main/java/org/apache/hadoop/hbase/AsyncConsoleAppender.java @@ -17,22 +17,19 @@ */ package org.apache.hadoop.hbase; -import org.apache.log4j.AsyncAppender; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.PatternLayout; import org.apache.yetus.audience.InterfaceAudience; /** * Logger class that buffers before trying to log to the specified console. */ @InterfaceAudience.Private -public class AsyncConsoleAppender extends AsyncAppender { - private final ConsoleAppender consoleAppender; +public class AsyncConsoleAppender extends org.apache.log4j.AsyncAppender { + private final org.apache.log4j.ConsoleAppender consoleAppender; public AsyncConsoleAppender() { super(); - consoleAppender = new ConsoleAppender(new PatternLayout( - "%d{ISO8601} %-5p [%t] %c{2}: %m%n")); + consoleAppender = new org.apache.log4j.ConsoleAppender( + new org.apache.log4j.PatternLayout("%d{ISO8601} %-5p [%t] %c{2}: %m%n")); this.addAppender(consoleAppender); } diff --git a/hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/InternalLog4jUtils.java b/hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/InternalLog4jUtils.java new file mode 100644 index 00000000000..28d29bf3013 --- /dev/null +++ b/hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/InternalLog4jUtils.java @@ -0,0 +1,70 @@ +/** + * 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. + */ +package org.apache.hadoop.hbase.logging; + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * The actual class for operating on log4j. + *

+ * This class will depend on log4j directly, so callers should not use this class directly to avoid + * introducing log4j dependencies to downstream users. Please call the methods in + * {@link Log4jUtils}, as they will call the methods here through reflection. + */ +@InterfaceAudience.Private +final class InternalLog4jUtils { + + private InternalLog4jUtils() { + } + + static void setLogLevel(String loggerName, String levelName) { + org.apache.log4j.Logger logger = org.apache.log4j.LogManager.getLogger(loggerName); + org.apache.log4j.Level level = org.apache.log4j.Level.toLevel(levelName.toUpperCase()); + if (!level.toString().equalsIgnoreCase(levelName)) { + throw new IllegalArgumentException("Unsupported log level " + levelName); + } + logger.setLevel(level); + } + + static String getEffectiveLevel(String loggerName) { + org.apache.log4j.Logger logger = org.apache.log4j.LogManager.getLogger(loggerName); + return logger.getEffectiveLevel().toString(); + } + + static Set getActiveLogFiles() throws IOException { + Set ret = new HashSet<>(); + org.apache.log4j.Appender a; + @SuppressWarnings("unchecked") + Enumeration e = + org.apache.log4j.Logger.getRootLogger().getAllAppenders(); + while (e.hasMoreElements()) { + a = e.nextElement(); + if (a instanceof org.apache.log4j.FileAppender) { + org.apache.log4j.FileAppender fa = (org.apache.log4j.FileAppender) a; + String filename = fa.getFile(); + ret.add(new File(filename)); + } + } + return ret; + } +} diff --git a/hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/Log4jUtils.java b/hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/Log4jUtils.java new file mode 100644 index 00000000000..9b3459194ab --- /dev/null +++ b/hbase-logging/src/main/java/org/apache/hadoop/hbase/logging/Log4jUtils.java @@ -0,0 +1,121 @@ +/** + * 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. + */ +package org.apache.hadoop.hbase.logging; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Set; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * A bridge class for operating on log4j, such as changing log level, etc. + *

+ * Will call the methods in {@link InternalLog4jUtils} to actually operate on the log4j stuff. + */ +@InterfaceAudience.Private +public final class Log4jUtils { + + private static final String INTERNAL_UTILS_CLASS_NAME = + "org.apache.hadoop.hbase.logging.InternalLog4jUtils"; + + private Log4jUtils() { + } + + // load class when calling to avoid introducing class not found exception on log4j when loading + // this class even without calling any of the methods below. + private static Method getMethod(String methodName, Class... args) { + try { + Class clazz = Class.forName(INTERNAL_UTILS_CLASS_NAME); + return clazz.getDeclaredMethod(methodName, args); + } catch (ClassNotFoundException | NoSuchMethodException e) { + throw new AssertionError("should not happen", e); + } + } + + private static void throwUnchecked(Throwable throwable) { + if (throwable instanceof RuntimeException) { + throw (RuntimeException) throwable; + } + if (throwable instanceof Error) { + throw (Error) throwable; + } + } + + public static void setLogLevel(String loggerName, String levelName) { + Method method = getMethod("setLogLevel", String.class, String.class); + try { + method.invoke(null, loggerName, levelName); + } catch (IllegalAccessException e) { + throw new AssertionError("should not happen", e); + } catch (InvocationTargetException e) { + throwUnchecked(e.getCause()); + throw new AssertionError("should not happen", e.getCause()); + } + } + + public static String getEffectiveLevel(String loggerName) { + Method method = getMethod("getEffectiveLevel", String.class); + try { + return (String) method.invoke(null, loggerName); + } catch (IllegalAccessException e) { + throw new AssertionError("should not happen", e); + } catch (InvocationTargetException e) { + throwUnchecked(e.getCause()); + throw new AssertionError("should not happen", e.getCause()); + } + } + + @SuppressWarnings("unchecked") + public static Set getActiveLogFiles() throws IOException { + Method method = getMethod("getActiveLogFiles"); + try { + return (Set) method.invoke(null); + } catch (IllegalAccessException e) { + throw new AssertionError("should not happen", e); + } catch (InvocationTargetException e) { + Throwable cause = e.getCause(); + throwUnchecked(cause); + if (cause instanceof IOException) { + throw (IOException) cause; + } + throw new AssertionError("should not happen", cause); + } + } + + /** + * Disables Zk- and HBase client logging + */ + public static void disableZkAndClientLoggers() { + // disable zookeeper log to avoid it mess up command output + setLogLevel("org.apache.zookeeper", "OFF"); + // disable hbase zookeeper tool log to avoid it mess up command output + setLogLevel("org.apache.hadoop.hbase.zookeeper", "OFF"); + // disable hbase client log to avoid it mess up command output + setLogLevel("org.apache.hadoop.hbase.client", "OFF"); + } + + /** + * Switches the logger for the given class to DEBUG level. + * @param clazz The class for which to switch to debug logging. + */ + public static void enableDebug(Class clazz) { + setLogLevel(clazz.getName(), "DEBUG"); + } +} diff --git a/hbase-asyncfs/src/test/resources/log4j.properties b/hbase-logging/src/test/resources/log4j.properties similarity index 100% rename from hbase-asyncfs/src/test/resources/log4j.properties rename to hbase-logging/src/test/resources/log4j.properties diff --git a/hbase-mapreduce/pom.xml b/hbase-mapreduce/pom.xml index 1d127dd2502..bf6c806c244 100644 --- a/hbase-mapreduce/pom.xml +++ b/hbase-mapreduce/pom.xml @@ -91,6 +91,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -245,10 +251,6 @@ test-jar test - - log4j - log4j - org.mockito mockito-core @@ -271,6 +273,26 @@ junit test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/util/MapreduceDependencyClasspathTool.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/util/MapreduceDependencyClasspathTool.java index 1187c18cba4..9432f309adb 100644 --- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/util/MapreduceDependencyClasspathTool.java +++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/util/MapreduceDependencyClasspathTool.java @@ -20,12 +20,11 @@ package org.apache.hadoop.hbase.util; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseInterfaceAudience; -import org.apache.yetus.audience.InterfaceAudience; +import org.apache.hadoop.hbase.logging.Log4jUtils; import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.yetus.audience.InterfaceAudience; /** * Generate a classpath string containing any jars required by mapreduce jobs. Specify @@ -63,10 +62,7 @@ public class MapreduceDependencyClasspathTool implements Tool { public static void main(String[] argv) throws Exception { // Silence the usual noise. This is probably fragile... - Logger logger = Logger.getLogger("org.apache.hadoop.hbase"); - if (logger != null) { - logger.setLevel(Level.WARN); - } + Log4jUtils.setLogLevel("org.apache.hadoop.hbase", "WARN"); System.exit(ToolRunner.run( HBaseConfiguration.create(), new MapreduceDependencyClasspathTool(), argv)); } diff --git a/hbase-mapreduce/src/test/resources/log4j.properties b/hbase-mapreduce/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-mapreduce/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-metrics-api/pom.xml b/hbase-metrics-api/pom.xml index 3e11c3ee290..20e805d3a85 100644 --- a/hbase-metrics-api/pom.xml +++ b/hbase-metrics-api/pom.xml @@ -83,6 +83,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -116,6 +122,26 @@ junit test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-metrics/pom.xml b/hbase-metrics/pom.xml index b7bdac5e40e..73b818cc15b 100644 --- a/hbase-metrics/pom.xml +++ b/hbase-metrics/pom.xml @@ -87,6 +87,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -124,6 +130,26 @@ mockito-core test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-procedure/pom.xml b/hbase-procedure/pom.xml index 3d76b2117be..60a39273f97 100644 --- a/hbase-procedure/pom.xml +++ b/hbase-procedure/pom.xml @@ -73,6 +73,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase.thirdparty hbase-shaded-protobuf @@ -113,6 +119,26 @@ mockito-core test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-procedure/src/test/resources/log4j.properties b/hbase-procedure/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-procedure/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-replication/pom.xml b/hbase-replication/pom.xml index 79fe62e2eff..d1b9101d696 100644 --- a/hbase-replication/pom.xml +++ b/hbase-replication/pom.xml @@ -67,6 +67,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-protocol-shaded @@ -114,6 +120,26 @@ junit test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-rest/pom.xml b/hbase-rest/pom.xml index a86fd8a0ee6..ce38e1edfde 100644 --- a/hbase-rest/pom.xml +++ b/hbase-rest/pom.xml @@ -153,6 +153,12 @@ javax.ws.rs-api + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -379,6 +385,26 @@ bcprov-jdk15on test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-rest/src/test/resources/log4j.properties b/hbase-rest/src/test/resources/log4j.properties deleted file mode 100644 index 4e5f014bc6c..00000000000 --- a/hbase-rest/src/test/resources/log4j.properties +++ /dev/null @@ -1,69 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE -log4j.logger.org.apache.directory=WARN diff --git a/hbase-rsgroup/pom.xml b/hbase-rsgroup/pom.xml index 2e40a85e8f6..e26aeea9542 100644 --- a/hbase-rsgroup/pom.xml +++ b/hbase-rsgroup/pom.xml @@ -77,6 +77,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-client @@ -160,13 +166,28 @@ zookeeper - log4j - log4j + org.mockito + mockito-core test - org.mockito - mockito-core + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j test diff --git a/hbase-rsgroup/src/test/resources/log4j.properties b/hbase-rsgroup/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-rsgroup/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-server/pom.xml b/hbase-server/pom.xml index 2e8d1ec80b5..65496742539 100644 --- a/hbase-server/pom.xml +++ b/hbase-server/pom.xml @@ -246,6 +246,12 @@ hbase-shaded-miscellaneous + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -420,14 +426,6 @@ org.apache.commons commons-math3 - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - org.apache.zookeeper zookeeper @@ -496,15 +494,6 @@ httpcore test - - - commons-logging - commons-logging - compile - org.apache.commons commons-crypto @@ -525,6 +514,26 @@ mockito-core test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java index ec8e5238c29..9569480eb26 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java @@ -31,10 +31,10 @@ import org.apache.hadoop.hbase.ServerMetrics; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.master.assignment.AssignmentManager; import org.apache.hadoop.hbase.master.assignment.RegionStateNode; -import org.apache.hadoop.hbase.monitoring.LogMonitoring; import org.apache.hadoop.hbase.monitoring.StateDumpServlet; import org.apache.hadoop.hbase.monitoring.TaskMonitor; import org.apache.hadoop.hbase.regionserver.RSDumpServlet; +import org.apache.hadoop.hbase.util.LogMonitoring; import org.apache.hadoop.hbase.util.Threads; import org.apache.yetus.audience.InterfaceAudience; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSDumpServlet.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSDumpServlet.java index d83ae47768d..11534674dcf 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSDumpServlet.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSDumpServlet.java @@ -25,14 +25,13 @@ import java.io.PrintWriter; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.apache.hadoop.hbase.ipc.CallQueueInfo; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.monitoring.LogMonitoring; +import org.apache.hadoop.hbase.ipc.CallQueueInfo; import org.apache.hadoop.hbase.monitoring.StateDumpServlet; import org.apache.hadoop.hbase.monitoring.TaskMonitor; +import org.apache.hadoop.hbase.util.LogMonitoring; import org.apache.hadoop.hbase.util.Threads; +import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private public class RSDumpServlet extends StateDumpServlet { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index c231cd74245..e0786538d52 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -53,8 +53,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.logging.impl.Jdk14Logger; -import org.apache.commons.logging.impl.Log4JLogger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -95,6 +93,7 @@ import org.apache.hadoop.hbase.io.hfile.ChecksumUtil; import org.apache.hadoop.hbase.io.hfile.HFile; import org.apache.hadoop.hbase.ipc.RpcServerInterface; import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException; +import org.apache.hadoop.hbase.logging.Log4jUtils; import org.apache.hadoop.hbase.mapreduce.MapreduceTestingShim; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.RegionState; @@ -144,14 +143,10 @@ import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.MiniMRCluster; import org.apache.hadoop.mapred.TaskLog; import org.apache.hadoop.minikdc.MiniKdc; -import org.apache.log4j.LogManager; import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.ZooKeeper.States; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.impl.Log4jLoggerAdapter; import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; import org.apache.hbase.thirdparty.com.google.common.io.Closeables; @@ -2995,18 +2990,14 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { /** * Switches the logger for the given class to DEBUG level. - * - * @param clazz The class for which to switch to debug logging. + * @param clazz The class for which to switch to debug logging. + * @deprecated In 2.3.0, will be removed in 4.0.0. Only support changing log level on log4j now as + * HBase only uses log4j. You should do this by your own as it you know which log + * framework you are using then set the log level to debug is very easy. */ + @Deprecated public void enableDebug(Class clazz) { - Logger l = LoggerFactory.getLogger(clazz); - if (l instanceof Log4JLogger) { - ((Log4JLogger) l).getLogger().setLevel(org.apache.log4j.Level.DEBUG); - } else if (l instanceof Log4jLoggerAdapter) { - LogManager.getLogger(clazz).setLevel(org.apache.log4j.Level.DEBUG); - } else if (l instanceof Jdk14Logger) { - ((Jdk14Logger) l).getLogger().setLevel(java.util.logging.Level.ALL); - } + Log4jUtils.enableDebug(clazz); } /** diff --git a/hbase-server/src/test/resources/log4j.properties b/hbase-server/src/test/resources/log4j.properties deleted file mode 100644 index 8e590b177c9..00000000000 --- a/hbase-server/src/test/resources/log4j.properties +++ /dev/null @@ -1,72 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -log4j.logger.org.apache.hadoop.hbase.mob.ManualMobMaintHFileCleaner=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -log4j.logger.io.netty.channel=DEBUG -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE -log4j.logger.org.apache.directory=WARN diff --git a/hbase-shaded/pom.xml b/hbase-shaded/pom.xml index 9736420340f..e030767cf8b 100644 --- a/hbase-shaded/pom.xml +++ b/hbase-shaded/pom.xml @@ -51,15 +51,14 @@ org.apache.hbase hbase-resource-bundle - ${project.version} true - + log4j log4j + true - org.slf4j slf4j-log4j12 diff --git a/hbase-shell/pom.xml b/hbase-shell/pom.xml index 837f320d08e..b54dcce9619 100644 --- a/hbase-shell/pom.xml +++ b/hbase-shell/pom.xml @@ -133,6 +133,12 @@ + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -180,6 +186,26 @@ junit test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-shell/src/test/resources/log4j.properties b/hbase-shell/src/test/resources/log4j.properties deleted file mode 100644 index c322699ced2..00000000000 --- a/hbase-shell/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-testing-util/pom.xml b/hbase-testing-util/pom.xml index d3eeb8c60fe..f3cf89c3749 100644 --- a/hbase-testing-util/pom.xml +++ b/hbase-testing-util/pom.xml @@ -31,6 +31,13 @@ HBase Testing Utilities. + + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -121,9 +128,25 @@ test-jar compile + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + org.slf4j slf4j-log4j12 + test + + + log4j + log4j + test diff --git a/hbase-thrift/pom.xml b/hbase-thrift/pom.xml index ae03d7d1b3e..da5a7d0beb4 100644 --- a/hbase-thrift/pom.xml +++ b/hbase-thrift/pom.xml @@ -147,6 +147,12 @@ + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-common @@ -254,6 +260,26 @@ kerb-simplekdc test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-zookeeper/pom.xml b/hbase-zookeeper/pom.xml index ccfb72d26cb..a2a571865ec 100644 --- a/hbase-zookeeper/pom.xml +++ b/hbase-zookeeper/pom.xml @@ -104,6 +104,12 @@ test-jar test + + org.apache.hbase + hbase-logging + test-jar + test + org.apache.hbase hbase-protocol-shaded @@ -138,10 +144,6 @@ org.slf4j slf4j-api - - log4j - log4j - org.apache.zookeeper zookeeper @@ -157,6 +159,26 @@ mockito-core test + + org.slf4j + jcl-over-slf4j + test + + + org.slf4j + jul-to-slf4j + test + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + diff --git a/hbase-zookeeper/src/test/resources/log4j.properties b/hbase-zookeeper/src/test/resources/log4j.properties deleted file mode 100644 index f599ea636e9..00000000000 --- a/hbase-zookeeper/src/test/resources/log4j.properties +++ /dev/null @@ -1,68 +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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=INFO,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=DEBUG -log4j.logger.org.apache.hadoop.hbase=DEBUG - -#These settings are workarounds against spurious logs from the minicluster. -#See HBASE-4709 -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN -log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN -log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN -# Enable this to get detailed connection error/retry logging. -# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/pom.xml b/pom.xml index bb7087c685f..808a9a06a7d 100755 --- a/pom.xml +++ b/pom.xml @@ -91,6 +91,7 @@ hbase-zookeeper hbase-hbtop hbase-asyncfs + hbase-logging scm:git:git://gitbox.apache.org/repos/asf/hbase.git @@ -667,6 +668,11 @@ jar-no-fork test-jar-no-fork + + + log4j.properties + + @@ -690,7 +696,6 @@ hbase-site.xml hdfs-site.xml - log4j.properties mapred-queues.xml mapred-site.xml @@ -941,6 +946,25 @@ + + banned-commons-logging + + enforce + + + + + + commons-logging:commons-logging + + + We don't use commons-logging any more, so do not depend on it directly. + + false + + + + check-aggregate-license @@ -989,8 +1013,17 @@ 512 Use SLF4j for logging - org.apache.commons.logging.Log - org.apache.commons.logging.LogFactory + org.apache.commons.logging.** + + + + false + 512 + + Do not use log4j directly in code, see Log4jUtils in hbase-logging for more details. + + + org.apache.log4j.** @@ -1497,6 +1530,18 @@ test-jar test + + org.apache.hbase + hbase-logging + ${project.version} + + + org.apache.hbase + hbase-logging + ${project.version} + test-jar + test + org.apache.hbase hbase-protocol-shaded @@ -1746,17 +1791,41 @@ findbugs-annotations ${findbugs-annotations.version} - + org.codehaus.jettison jettison ${jettison.version} + + org.slf4j + slf4j-api + ${slf4j.version} + org.slf4j slf4j-log4j12 ${slf4j.version} + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.slf4j + jul-to-slf4j + ${slf4j.version} + log4j log4j @@ -1770,11 +1839,6 @@ - - org.slf4j - slf4j-api - ${slf4j.version} - com.github.ben-manes.caffeine caffeine @@ -1856,6 +1920,14 @@ io.netty netty + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -2920,10 +2992,18 @@ org.codehaus.jackson jackson-mapper-asl - - com.google.guava - guava - + + com.google.guava + guava + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -2943,6 +3023,14 @@ javax.servlet servlet-api + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -2964,6 +3052,14 @@ javax.servlet servlet-api + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -3003,10 +3099,18 @@ org.codehaus.jackson jackson-mapper-asl - - com.google.guava - guava - + + com.google.guava + guava + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -3048,6 +3152,14 @@ com.sun.jersey jersey-core + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -3077,6 +3189,14 @@ net.minidev json-smart + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -3132,6 +3252,14 @@ org.codehause.jackson jackson-mapper-asl + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + @@ -3213,15 +3341,32 @@ com.google.code.findbugs jsr305 + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + - org.apache.hadoop - hadoop-minikdc - ${hadoop-three.version} - test - - + org.apache.hadoop + hadoop-minikdc + ${hadoop-three.version} + test + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + org.apache.hadoop hadoop-distcp