From 5ae4b62876045bcccbfcaac0a42842cef1cd25c5 Mon Sep 17 00:00:00 2001 From: TengYao Chi Date: Wed, 1 Jan 2025 21:06:01 +0800 Subject: [PATCH] KAFKA-18347 Add tools-log4j2.yaml to config and remove unsed tools-log4j.properties from config (#18351) Reviewers: Chia-Ping Tsai --- bin/kafka-run-class.sh | 6 +++--- bin/windows/kafka-run-class.bat | 2 +- ...ols-log4j.properties => tools-log4j2.yaml} | 21 ++++++++++++++----- 3 files changed, 20 insertions(+), 9 deletions(-) rename config/{tools-log4j.properties => tools-log4j2.yaml} (71%) diff --git a/bin/kafka-run-class.sh b/bin/kafka-run-class.sh index cab73fc7f38..8bd1b17623b 100755 --- a/bin/kafka-run-class.sh +++ b/bin/kafka-run-class.sh @@ -23,7 +23,7 @@ fi # WINDOWS_OS_FORMAT == 1 if Cygwin or MinGW is detected, else 0. if [[ $(uname -a) =~ "CYGWIN" || $(uname -a) =~ "MINGW" || $(uname -a) =~ "MSYS" ]]; then WINDOWS_OS_FORMAT=1 - export MSYS2_ARG_CONV_EXCL="-Xlog:gc*:file=;-Dlog4j.configuration=;$MSYS2_ARG_CONV_EXCL" + export MSYS2_ARG_CONV_EXCL="-Xlog:gc*:file=;-Dlog4j2.configurationFile=;$MSYS2_ARG_CONV_EXCL" else WINDOWS_OS_FORMAT=0 fi @@ -220,10 +220,10 @@ fi # Log4j settings if [ -z "$KAFKA_LOG4J_OPTS" ]; then # Log to console. This is a tool. - LOG4J_DIR="$base_dir/config/tools-log4j.properties" + LOG4J_DIR="$base_dir/config/tools-log4j2.yaml" # If Cygwin is detected, LOG4J_DIR is converted to Windows format. (( WINDOWS_OS_FORMAT )) && LOG4J_DIR=$(cygpath --path --mixed "${LOG4J_DIR}") - KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:${LOG4J_DIR}" + KAFKA_LOG4J_OPTS="-Dlog4j2.configurationFile=${LOG4J_DIR}" else if echo "$KAFKA_LOG4J_OPTS" | grep -E "log4j\.[^[:space:]]+(\.properties|\.xml)$"; then # Enable Log4j 1.x configuration compatibility mode for Log4j 2 diff --git a/bin/windows/kafka-run-class.bat b/bin/windows/kafka-run-class.bat index a09b79c6869..ca151e5df96 100755 --- a/bin/windows/kafka-run-class.bat +++ b/bin/windows/kafka-run-class.bat @@ -116,7 +116,7 @@ IF ["%LOG_DIR%"] EQU [""] ( rem Log4j settings IF ["%KAFKA_LOG4J_OPTS%"] EQU [""] ( - set KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:%BASE_DIR%/config/tools-log4j.properties + set KAFKA_LOG4J_OPTS=-Dlog4j2.configurationFile=file:%BASE_DIR%/config/tools-log4j2.yaml ) ELSE ( rem Check if Log4j 1.x configuration options are present in KAFKA_LOG4J_OPTS echo %KAFKA_LOG4J_OPTS% | findstr /r /c:"log4j\.[^ ]*(\.properties|\.xml)$" >nul diff --git a/config/tools-log4j.properties b/config/tools-log4j2.yaml similarity index 71% rename from config/tools-log4j.properties rename to config/tools-log4j2.yaml index b19e343265f..bb5d1adf41b 100644 --- a/config/tools-log4j.properties +++ b/config/tools-log4j2.yaml @@ -12,10 +12,21 @@ # 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. +Configuration: + Properties: + Property: + - name: "logPattern" + value: "[%d] %p %m (%c)%n" -log4j.rootLogger=WARN, stderr + Appenders: + Console: + name: STDERR + target: SYSTEM_ERR + PatternLayout: + pattern: "${logPattern}" + Loggers: + Root: + level: WARN + AppenderRef: + - ref: STDERR -log4j.appender.stderr=org.apache.log4j.ConsoleAppender -log4j.appender.stderr.layout=org.apache.log4j.PatternLayout -log4j.appender.stderr.layout.ConversionPattern=[%d] %p %m (%c)%n -log4j.appender.stderr.Target=System.err