Opt into generated log4j2.xml configuration (#3856)

This commit is contained in:
Geoff Bourne
2026-01-08 07:25:01 -06:00
committed by GitHub
parent 9c01462c0c
commit f8ff8a7b8a
4 changed files with 10 additions and 4 deletions
+1
View File
@@ -175,6 +175,7 @@ jobs:
MINECRAFT_VERSION: ${{ matrix.mcVersion }} MINECRAFT_VERSION: ${{ matrix.mcVersion }}
VARIANT: ${{ matrix.variant }} VARIANT: ${{ matrix.variant }}
CF_API_KEY: ${{ secrets.CF_API_KEY }} CF_API_KEY: ${{ secrets.CF_API_KEY }}
GH_TOKEN: ${{ github.token }}
run: | run: |
tests/test.sh tests/test.sh
+1
View File
@@ -92,5 +92,6 @@ jobs:
VARIANT: ${{ matrix.variant }} VARIANT: ${{ matrix.variant }}
CF_API_KEY: ${{ secrets.CF_API_KEY }} CF_API_KEY: ${{ secrets.CF_API_KEY }}
DEBUG: ${{ runner.debug }} DEBUG: ${{ runner.debug }}
GH_TOKEN: ${{ github.token }}
run: | run: |
tests/test.sh tests/test.sh
+2
View File
@@ -81,6 +81,8 @@ The openj9 image tags include specific variables to simplify configuration:
The image now uses a templated log4j2 configuration based on PaperMC's logging setup, which is automatically applied for versions that don't require Log4j security patches. This configuration provides rolling logs and advanced logging features by default. The image now uses a templated log4j2 configuration based on PaperMC's logging setup, which is automatically applied for versions that don't require Log4j security patches. This configuration provides rolling logs and advanced logging features by default.
Set the environment variable `GENERATE_LOG4J2_CONFIG` to "true" to enable the following features.
### Customization via environment variables ### Customization via environment variables
You can customize various aspects of the logging behavior using environment variables: You can customize various aspects of the logging behavior using environment variables:
+6 -4
View File
@@ -47,7 +47,7 @@ if [ -n "$ICON" ]; then
fi fi
fi fi
canUseRollingLogs=true useGeneratedLogs=${GENERATE_LOG4J2_CONFIG:-false}
useFallbackJvmFlag=false useFallbackJvmFlag=false
SERVER_DIR="$baseDataDir" SERVER_DIR="$baseDataDir"
@@ -65,7 +65,7 @@ patchLog4jConfig() {
return 1 return 1
fi fi
JVM_OPTS="-Dlog4j.configurationFile=${file} ${JVM_OPTS}" JVM_OPTS="-Dlog4j.configurationFile=${file} ${JVM_OPTS}"
canUseRollingLogs=false useGeneratedLogs=false
} }
# Temporarily disable debugging output # Temporarily disable debugging output
@@ -104,7 +104,8 @@ elif versionLessThan 1.18.1; then
fi fi
# Set up log4j2 configuration with templating support # Set up log4j2 configuration with templating support
if ${canUseRollingLogs}; then LOGFILE="${SERVER_DIR}/log4j2.xml"
if ${useGeneratedLogs}; then
# Set up log configuration defaults # Set up log configuration defaults
: "${LOG_LEVEL:=info}" : "${LOG_LEVEL:=info}"
: "${ROLLING_LOG_MAX_FILES:=1000}" : "${ROLLING_LOG_MAX_FILES:=1000}"
@@ -128,7 +129,6 @@ if ${canUseRollingLogs}; then
export LOG_LEVEL ROLLING_LOG_FILE_PATTERN ROLLING_LOG_MAX_FILES export LOG_LEVEL ROLLING_LOG_FILE_PATTERN ROLLING_LOG_MAX_FILES
export LOG_CONSOLE_FORMAT LOG_TERMINAL_FORMAT LOG_FILE_FORMAT export LOG_CONSOLE_FORMAT LOG_TERMINAL_FORMAT LOG_FILE_FORMAT
LOGFILE="${SERVER_DIR}/log4j2.xml"
# Always regenerate if file doesn't exist # Always regenerate if file doesn't exist
if [ ! -e "$LOGFILE" ] || isTrue "${REGENERATE_LOG4J2:-true}"; then if [ ! -e "$LOGFILE" ] || isTrue "${REGENERATE_LOG4J2:-true}"; then
@@ -176,6 +176,8 @@ elif isTrue "${ENABLE_ROLLING_LOGS:-false}"; then
# Legacy behavior: error if rolling logs explicitly requested but not possible # Legacy behavior: error if rolling logs explicitly requested but not possible
logError "Using rolling logs is currently not possible in the selected version due to CVE-2021-44228" logError "Using rolling logs is currently not possible in the selected version due to CVE-2021-44228"
exit 1 exit 1
else
rm -f "${LOGFILE}"
fi fi
# Optional disable console # Optional disable console