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.
This commit is contained in:
CalDescent
2022-01-02 20:50:38 +00:00
parent 5157ccf7c0
commit b1c1634950
4 changed files with 35 additions and 2 deletions

View File

@@ -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.

View File

@@ -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
}
}
}
}