From 58e3f56f0ebc3bf032cc818f09c28476bfbd4755 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Tue, 14 Jan 2025 18:11:06 +0800 Subject: [PATCH] [fix][misc] Honor dynamic log levels in log4j2.yaml Signed-off-by: Zixuan Liu --- bin/pulsar | 12 ++++++++---- bin/pulsar-admin-common.cmd | 12 ++++++++---- bin/pulsar-perf | 12 ++++++++---- docker/pulsar/Dockerfile | 2 -- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bin/pulsar b/bin/pulsar index 0125dd81e8bb4..934a87d5e318e 100755 --- a/bin/pulsar +++ b/bin/pulsar @@ -303,8 +303,6 @@ else fi PULSAR_LOG_APPENDER=${PULSAR_LOG_APPENDER:-"RoutingAppender"} -PULSAR_LOG_LEVEL=${PULSAR_LOG_LEVEL:-"info"} -PULSAR_LOG_ROOT_LEVEL=${PULSAR_LOG_ROOT_LEVEL:-"${PULSAR_LOG_LEVEL}"} PULSAR_ROUTING_APPENDER_DEFAULT=${PULSAR_ROUTING_APPENDER_DEFAULT:-"Console"} if [ ! -d "$PULSAR_LOG_DIR" ]; then mkdir -p "$PULSAR_LOG_DIR" @@ -314,8 +312,14 @@ PULSAR_LOG_IMMEDIATE_FLUSH="${PULSAR_LOG_IMMEDIATE_FLUSH:-"false"}" #Configure log configuration system properties OPTS="$OPTS -Dpulsar.log.appender=$PULSAR_LOG_APPENDER" OPTS="$OPTS -Dpulsar.log.dir=$PULSAR_LOG_DIR" -OPTS="$OPTS -Dpulsar.log.level=$PULSAR_LOG_LEVEL" -OPTS="$OPTS -Dpulsar.log.root.level=$PULSAR_LOG_ROOT_LEVEL" +if [ -n "$PULSAR_LOG_LEVEL" ]; then + OPTS="$OPTS -Dpulsar.log.level=$PULSAR_LOG_LEVEL" +fi +if [ -n "$PULSAR_LOG_ROOT_LEVEL" ]; then + OPTS="$OPTS -Dpulsar.log.root.level=$PULSAR_LOG_ROOT_LEVEL" +elif [ -n "$PULSAR_LOG_LEVEL" ]; then + OPTS="$OPTS -Dpulsar.log.root.level=$PULSAR_LOG_LEVEL" +fi OPTS="$OPTS -Dpulsar.log.immediateFlush=$PULSAR_LOG_IMMEDIATE_FLUSH" OPTS="$OPTS -Dpulsar.routing.appender.default=$PULSAR_ROUTING_APPENDER_DEFAULT" # Configure log4j2 to disable servlet webapp detection so that Garbage free logging can be used diff --git a/bin/pulsar-admin-common.cmd b/bin/pulsar-admin-common.cmd index c59f0e9b424d3..c45800fd7bb64 100644 --- a/bin/pulsar-admin-common.cmd +++ b/bin/pulsar-admin-common.cmd @@ -83,14 +83,18 @@ set "OPTS=%OPTS% %PULSAR_EXTRA_OPTS%" if "%PULSAR_LOG_DIR%" == "" set "PULSAR_LOG_DIR=%PULSAR_HOME%\logs" if "%PULSAR_LOG_APPENDER%" == "" set "PULSAR_LOG_APPENDER=RoutingAppender" -if "%PULSAR_LOG_LEVEL%" == "" set "PULSAR_LOG_LEVEL=info" -if "%PULSAR_LOG_ROOT_LEVEL%" == "" set "PULSAR_LOG_ROOT_LEVEL=%PULSAR_LOG_LEVEL%" if "%PULSAR_ROUTING_APPENDER_DEFAULT%" == "" set "PULSAR_ROUTING_APPENDER_DEFAULT=Console" if "%PULSAR_LOG_IMMEDIATE_FLUSH%" == "" set "PULSAR_LOG_IMMEDIATE_FLUSH=false" set "OPTS=%OPTS% -Dpulsar.log.appender=%PULSAR_LOG_APPENDER%" set "OPTS=%OPTS% -Dpulsar.log.dir=%PULSAR_LOG_DIR%" -set "OPTS=%OPTS% -Dpulsar.log.level=%PULSAR_LOG_LEVEL%" -set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%" +if not "%PULSAR_LOG_LEVEL%" == "" set "OPTS=%OPTS% -Dpulsar.log.level=%PULSAR_LOG_LEVEL%" +if not "%PULSAR_LOG_ROOT_LEVEL%" == "" ( + set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%" +) else ( + if not "%PULSAR_LOG_LEVEL%" == "" ( + set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_LEVEL%" + ) +) set "OPTS=%OPTS% -Dpulsar.log.immediateFlush=%PULSAR_LOG_IMMEDIATE_FLUSH%" set "OPTS=%OPTS% -Dpulsar.routing.appender.default=%PULSAR_ROUTING_APPENDER_DEFAULT%" \ No newline at end of file diff --git a/bin/pulsar-perf b/bin/pulsar-perf index 9108a42ef994f..e785cc585804c 100755 --- a/bin/pulsar-perf +++ b/bin/pulsar-perf @@ -125,14 +125,18 @@ OPTS="$OPTS $PULSAR_EXTRA_OPTS" # log directory & file PULSAR_LOG_APPENDER=${PULSAR_LOG_APPENDER:-"Console"} PULSAR_LOG_FILE=${PULSAR_LOG_FILE:-"pulsar-perftest.log"} -PULSAR_LOG_LEVEL=${PULSAR_LOG_LEVEL:-"info"} -PULSAR_LOG_ROOT_LEVEL=${PULSAR_LOG_ROOT_LEVEL:-"${PULSAR_LOG_LEVEL}"} PULSAR_LOG_IMMEDIATE_FLUSH="${PULSAR_LOG_IMMEDIATE_FLUSH:-"false"}" #Configure log configuration system properties OPTS="$OPTS -Dpulsar.log.appender=$PULSAR_LOG_APPENDER" -OPTS="$OPTS -Dpulsar.log.level=$PULSAR_LOG_LEVEL" -OPTS="$OPTS -Dpulsar.log.root.level=$PULSAR_LOG_ROOT_LEVEL" +if [ -n "$PULSAR_LOG_LEVEL" ]; then + OPTS="$OPTS -Dpulsar.log.level=$PULSAR_LOG_LEVEL" +fi +if [ -n "$PULSAR_LOG_ROOT_LEVEL" ]; then + OPTS="$OPTS -Dpulsar.log.root.level=$PULSAR_LOG_ROOT_LEVEL" +elif [ -n "$PULSAR_LOG_LEVEL" ]; then + OPTS="$OPTS -Dpulsar.log.root.level=$PULSAR_LOG_LEVEL" +fi OPTS="$OPTS -Dpulsar.log.immediateFlush=$PULSAR_LOG_IMMEDIATE_FLUSH" OPTS="$OPTS -Dpulsar.log.dir=$PULSAR_LOG_DIR" OPTS="$OPTS -Dpulsar.log.file=$PULSAR_LOG_FILE" diff --git a/docker/pulsar/Dockerfile b/docker/pulsar/Dockerfile index 6f1f41755c919..63fadb62e64ae 100644 --- a/docker/pulsar/Dockerfile +++ b/docker/pulsar/Dockerfile @@ -135,8 +135,6 @@ COPY --from=snappy-java /tmp/libsnappyjava.so /usr/lib/libsnappyjava.so # The default is /pulsat/bin and cannot be written. ENV PULSAR_PID_DIR=/pulsar/logs -ENV PULSAR_ROOT_LOGGER=INFO,CONSOLE - COPY --from=pulsar /pulsar /pulsar WORKDIR /pulsar