From b1c1634950e51af2a9ed43d9c3c6068e9c074145 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sun, 2 Jan 2022 20:50:38 +0000 Subject: [PATCH] Updated log4j to 2.17.1 This involves modifying the log4j2.properties file on node startup to fix an incompatibility with ${dirname:-}. Thanks to AlphaX Projects for tracking down this incompatibility. --- log4j2.properties | 2 +- pom.xml | 2 +- .../org/qortal/controller/Controller.java | 2 ++ .../java/org/qortal/utils/LoggingUtils.java | 31 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/qortal/utils/LoggingUtils.java diff --git a/log4j2.properties b/log4j2.properties index fdbf51dd..44e1b1e3 100644 --- a/log4j2.properties +++ b/log4j2.properties @@ -61,7 +61,7 @@ appender.rolling.type = RollingFile appender.rolling.name = FILE appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -appender.rolling.filePattern = ${dirname:-}${filename}.%i +appender.rolling.filePattern = ./${filename}.%i appender.rolling.policy.type = SizeBasedTriggeringPolicy appender.rolling.policy.size = 4MB # Set the immediate flush to true (default) diff --git a/pom.xml b/pom.xml index e6b6cea5..59f4e63b 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 2.5.1 2.29.1 9.4.29.v20200521 - 2.12.1 + 2.17.1 UTF-8 1.7.12 2.0.9 diff --git a/src/main/java/org/qortal/controller/Controller.java b/src/main/java/org/qortal/controller/Controller.java index f5ff5763..aff35b38 100644 --- a/src/main/java/org/qortal/controller/Controller.java +++ b/src/main/java/org/qortal/controller/Controller.java @@ -366,6 +366,8 @@ public class Controller extends Thread { // Entry point public static void main(String[] args) { + LoggingUtils.fixLegacyLog4j2Properties(); + LOGGER.info("Starting up..."); // Potential GUI startup with splash screen, etc. diff --git a/src/main/java/org/qortal/utils/LoggingUtils.java b/src/main/java/org/qortal/utils/LoggingUtils.java new file mode 100644 index 00000000..cb8af45f --- /dev/null +++ b/src/main/java/org/qortal/utils/LoggingUtils.java @@ -0,0 +1,31 @@ +package org.qortal.utils; + +import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class LoggingUtils { + + public static void fixLegacyLog4j2Properties() { + Path log4j2PropertiesPath = Paths.get("log4j2.properties"); + if (Files.exists(log4j2PropertiesPath)) { + try { + String content = FileUtils.readFileToString(log4j2PropertiesPath.toFile(), "UTF-8"); + if (content.contains("${dirname:-}")) { + content = content.replace("${dirname:-}", "./"); + FileUtils.writeStringToFile(log4j2PropertiesPath.toFile(), content, "UTF-8"); + + // Force reload the log4j2.properties file + ((org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false)).reconfigure(); + } + } catch (IOException e) { + // Not much we can do here + } + } + } + +}