Skip to content

Commit 1fce264

Browse files
authored
update archetype: reconfigure plugin's log context correctly (#146)
1 parent b7f17af commit 1fce264

File tree

1 file changed

+4
-10
lines changed
  • bifromq-plugin/bifromq-plugin-archetype/src/main/resources/archetype-resources/plugin-build/src/main/java

1 file changed

+4
-10
lines changed

bifromq-plugin/bifromq-plugin-archetype/src/main/resources/archetype-resources/plugin-build/src/main/java/__pluginName__.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.apache.bifromq.plugin.BifroMQPlugin;
2323
import org.apache.bifromq.plugin.BifroMQPluginDescriptor;
24-
import org.apache.logging.log4j.LogManager;
25-
import org.apache.logging.log4j.core.LoggerContext;
2624
import org.apache.logging.log4j.core.config.Configurator;
2725
import org.slf4j.Logger;
2826
import org.slf4j.LoggerFactory;
@@ -66,18 +64,14 @@ private void configureLoggerContext(Path rootPath) {
6664
Path configPath = rootPath.resolve(LOG4J2_CONFIG_FILE).toAbsolutePath();
6765
File log4jConfig = configPath.toFile();
6866
if (log4jConfig.exists()) {
69-
// Shutdown any existing context to avoid resource leaks
70-
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
71-
ctx.stop();
72-
73-
// Initialize a new LoggerContext with the plugin-specific configuration
74-
Configurator.initialize(null, configPath.toString());
75-
log.info("Loaded Log4j2 configuration from {}", configPath);
67+
// reconfigure Log4j2 with the plugin-specific configuration
68+
Configurator.reconfigure(log4jConfig.toURI());
69+
log.info("Loaded Log4j configuration from {}", configPath);
7670
} else {
7771
log.warn("log4j2.xml not found for {}", getClass().getName());
7872
}
7973
} catch (Exception e) {
80-
log.error("Failed to configure Log4j2 for {}", getClass().getName(), e);
74+
log.error("Failed to configure Log4j for {}", getClass().getName(), e);
8175
}
8276
}
8377

0 commit comments

Comments
 (0)