Skip to content

Commit

Permalink
HBASE-26802 Backport the log4j2 changes to branch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Apache9 committed Mar 5, 2022
1 parent 0a7e49c commit 745c0ae
Show file tree
Hide file tree
Showing 79 changed files with 3,348 additions and 2,797 deletions.
20 changes: 9 additions & 11 deletions bin/hbase
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,13 @@ else
# make it easier to check for shaded/not later on.
shaded_jar=""
fi
# here we will add slf4j-api, commons-logging, jul-to-slf4j, jcl-over-slf4j
# to classpath, as they are all logging bridges. Only exclude log4j* so we
# will not actually log anything out. Add it later if necessary
for f in "${HBASE_HOME}"/lib/client-facing-thirdparty/*.jar; do
if [[ ! "${f}" =~ ^.*/htrace-core-3.*\.jar$ ]] && \
[ "${f}" != "htrace-core.jar$" ] && \
[[ ! "${f}" =~ ^.*/slf4j-log4j.*$ ]]; then
[[ "${f}" != "htrace-core.jar$" ]] && \
[[ ! "${f}" =~ ^.*/log4j.*$ ]]; then
CLASSPATH="${CLASSPATH}:${f}"
fi
done
Expand Down Expand Up @@ -671,7 +674,7 @@ elif [ "$COMMAND" = "mapredcp" ] ; then
for f in "${HBASE_HOME}"/lib/client-facing-thirdparty/*.jar; do
if [[ ! "${f}" =~ ^.*/htrace-core-3.*\.jar$ ]] && \
[ "${f}" != "htrace-core.jar$" ] && \
[[ ! "${f}" =~ ^.*/slf4j-log4j.*$ ]]; then
[[ ! "${f}" =~ ^.*/log4j.*$ ]]; then
echo -n ":${f}"
fi
done
Expand Down Expand Up @@ -720,8 +723,8 @@ elif [ "$COMMAND" = "hbtop" ] ; then
done
fi

if [ -f "${HBASE_HOME}/conf/log4j-hbtop.properties" ] ; then
HBASE_HBTOP_OPTS="${HBASE_HBTOP_OPTS} -Dlog4j.configuration=file:${HBASE_HOME}/conf/log4j-hbtop.properties"
if [ -f "${HBASE_HOME}/conf/log4j2-hbtop.properties" ] ; then
HBASE_HBTOP_OPTS="${HBASE_HBTOP_OPTS} -Dlog4j2.configurationFile=file:${HBASE_HOME}/conf/log4j2-hbtop.properties"
fi
HBASE_OPTS="${HBASE_OPTS} ${HBASE_HBTOP_OPTS}"
else
Expand Down Expand Up @@ -796,10 +799,6 @@ HBASE_OPTS="$HBASE_OPTS -Dhbase.log.file=$HBASE_LOGFILE"
HBASE_OPTS="$HBASE_OPTS -Dhbase.home.dir=$HBASE_HOME"
HBASE_OPTS="$HBASE_OPTS -Dhbase.id.str=$HBASE_IDENT_STRING"
HBASE_OPTS="$HBASE_OPTS -Dhbase.root.logger=${HBASE_ROOT_LOGGER:-INFO,console}"
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
HBASE_OPTS="$HBASE_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_LIBRARY_PATH"
fi

# Enable security logging on the master and regionserver only
if [ "$COMMAND" = "master" ] || [ "$COMMAND" = "regionserver" ]; then
Expand All @@ -810,10 +809,9 @@ fi

HEAP_SETTINGS="$JAVA_HEAP_MAX $JAVA_OFFHEAP_MAX"
# by now if we're running a command it means we need logging
for f in ${HBASE_HOME}/lib/client-facing-thirdparty/slf4j-log4j*.jar; do
for f in ${HBASE_HOME}/lib/client-facing-thirdparty/log4j*.jar; do
if [ -f "${f}" ]; then
CLASSPATH="${CLASSPATH}:${f}"
break
fi
done

Expand Down
16 changes: 12 additions & 4 deletions bin/hbase-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,20 @@ JAVA=$JAVA_HOME/bin/java
export HBASE_LOG_PREFIX=hbase-$HBASE_IDENT_STRING-$command-$HOSTNAME
export HBASE_LOGFILE=$HBASE_LOG_PREFIX.log

if [ -z "${HBASE_ROOT_LOGGER}" ]; then
export HBASE_ROOT_LOGGER=${HBASE_ROOT_LOGGER:-"INFO,RFA"}
if [ -z "${HBASE_ROOT_LOGGER_LEVEL}" ]; then
export HBASE_ROOT_LOGGER_LEVEL=${HBASE_ROOT_LOGGER_LEVEL:-"INFO"}
fi

if [ -z "${HBASE_SECURITY_LOGGER}" ]; then
export HBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"}
if [ -z "${HBASE_ROOT_LOGGER_APPENDER}" ]; then
export HBASE_ROOT_LOGGER_APPENDER=${HBASE_ROOT_LOGGER_APPENDER:-"RFA"}
fi

if [ -z "${HBASE_SECURITY_LOGGER_LEVEL}" ]; then
export HBASE_SECURITY_LOGGER_LEVEL=${HBASE_SECURITY_LOGGER_LEVEL:-"INFO"}
fi

if [ -z "${HBASE_SECURITY_LOGGER_APPENDER}" ]; then
export HBASE_SECURITY_LOGGER_APPENDER=${HBASE_SECURITY_LOGGER_APPENDER:-"RFAS"}
fi

HBASE_LOGOUT=${HBASE_LOGOUT:-"$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.out"}
Expand Down
2 changes: 2 additions & 0 deletions bin/hbase.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ set HBASE_OPTS=%HBASE_OPTS% -Djava.util.logging.config.class="org.apache.hadoop.
if not defined HBASE_ROOT_LOGGER (
set HBASE_ROOT_LOGGER=INFO,console
)

set HBASE_OPTS=%HBASE_OPTS% -Dhbase.root.logger="%HBASE_ROOT_LOGGER%"

if defined JAVA_LIBRARY_PATH (
Expand All @@ -348,6 +349,7 @@ if not defined HBASE_SECURITY_LOGGER (
set HBASE_SECURITY_LOGGER=INFO,DRFAS
)
)

set HBASE_OPTS=%HBASE_OPTS% -Dhbase.security.logger="%HBASE_SECURITY_LOGGER%"

set HEAP_SETTINGS=%JAVA_HEAP_MAX% %JAVA_OFFHEAP_MAX%
Expand Down
5 changes: 4 additions & 1 deletion conf/hbase-env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@rem set HBASE_OFFHEAPSIZE=1000

@rem For example, to allocate 8G of offheap, to 8G:
@rem etHBASE_OFFHEAPSIZE=8G
@rem set HBASE_OFFHEAPSIZE=8G

@rem Extra Java runtime options.
@rem Below are what we set by default. May only work with SUN JVM.
Expand Down Expand Up @@ -82,6 +82,9 @@ set HBASE_OPTS=%HBASE_OPTS% "-XX:+UseConcMarkSweepGC" "-Djava.net.preferIPv4Stac
@rem Tell HBase whether it should manage it's own instance of ZooKeeper or not.
@rem set HBASE_MANAGES_ZK=true

@rem Tell HBase the logger level and appenders
@rem set HBASE_ROOT_LOGGER=INFO,DRFA

@rem Uncomment to enable trace, you can change the options to use other exporters such as jaeger or
@rem zipkin. See https://github.com/open-telemetry/opentelemetry-java-instrumentation on how to
@rem configure exporters and other components through system properties.
Expand Down
4 changes: 2 additions & 2 deletions conf/hbase-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@
# export HBASE_MANAGES_ZK=true

# The default log rolling policy is RFA, where the log file is rolled as per the size defined for the
# RFA appender. Please refer to the log4j.properties file to see more details on this appender.
# RFA appender. Please refer to the log4j2.properties file to see more details on this appender.
# In case one needs to do log rolling on a date change, one should set the environment property
# HBASE_ROOT_LOGGER to "<DESIRED_LOG LEVEL>,DRFA".
# For example:
# HBASE_ROOT_LOGGER=INFO,DRFA
# export HBASE_ROOT_LOGGER=INFO,DRFA
# The reason for changing default to RFA is to avoid the boundary case of filling out disk space as
# DRFA doesn't put any cap on the log size. Please refer to HBase-5655 for more context.

Expand Down
27 changes: 0 additions & 27 deletions conf/log4j-hbtop.properties

This file was deleted.

139 changes: 0 additions & 139 deletions conf/log4j.properties

This file was deleted.

35 changes: 35 additions & 0 deletions conf/log4j2-hbtop.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#/**
# * 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.
# */

status = warn
dest = err
name = PropertiesConfig

# console
appender.console.type = Console
appender.console.target = SYSTEM_ERR
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{ISO8601} %-5p [%t] %c{2}: %m%n

rootLogger = WARN,console

# ZooKeeper will still put stuff at WARN
logger.zookeeper.name = org.apache.zookeeper
logger.zookeeper.level = ERROR

Loading

0 comments on commit 745c0ae

Please sign in to comment.