From cfd0fb77d7ac3d7474a46112d55a230b3e7007b4 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Tue, 28 May 2024 22:52:08 +0800 Subject: [PATCH] Fix empty log file when running via JAR --- src/main/java/pascal/taie/Main.java | 2 +- src/main/java/pascal/taie/config/LoggerConfigs.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/pascal/taie/Main.java b/src/main/java/pascal/taie/Main.java index 335b4fe75..d84887fd2 100644 --- a/src/main/java/pascal/taie/Main.java +++ b/src/main/java/pascal/taie/Main.java @@ -60,8 +60,8 @@ public static void main(String... args) { } buildWorld(options, plan.analyses()); executePlan(plan); - LoggerConfigs.reconfigure(); }, "Tai-e"); + LoggerConfigs.reconfigure(); } /** diff --git a/src/main/java/pascal/taie/config/LoggerConfigs.java b/src/main/java/pascal/taie/config/LoggerConfigs.java index ebc686133..10ae4da23 100644 --- a/src/main/java/pascal/taie/config/LoggerConfigs.java +++ b/src/main/java/pascal/taie/config/LoggerConfigs.java @@ -60,12 +60,12 @@ private LoggerConfigs() { */ public static void reconfigure() { // stop the last configuration - Configuration config = ((LoggerContext) LogManager.getContext(false)) - .getConfiguration(); + LoggerContext ctx = ((org.apache.logging.log4j.core.Logger) logger).getContext(); + Configuration config = ctx.getConfiguration(); config.stop(); // re-fetch the configuration and reconfigure it if (config instanceof Reconfigurable reconfigurableConfig) { - Configurator.reconfigure(reconfigurableConfig.reconfigure()); + ctx.reconfigure(reconfigurableConfig.reconfigure()); } } @@ -73,8 +73,8 @@ public static void reconfigure() { * Set the log output file based on the given output dir. */ public static void setOutput(File outputDir) { - Configuration config = ((LoggerContext) LogManager.getContext(false)) - .getConfiguration(); + LoggerContext ctx = ((org.apache.logging.log4j.core.Logger) logger).getContext(); + Configuration config = ctx.getConfiguration(); // new a file appender FileAppender fileAppender = FileAppender .newBuilder()