|
21 | 21 |
|
22 | 22 | import org.apache.bifromq.plugin.BifroMQPlugin;
|
23 | 23 | import org.apache.bifromq.plugin.BifroMQPluginDescriptor;
|
24 |
| -import org.apache.logging.log4j.LogManager; |
25 |
| -import org.apache.logging.log4j.core.LoggerContext; |
26 | 24 | import org.apache.logging.log4j.core.config.Configurator;
|
27 | 25 | import org.slf4j.Logger;
|
28 | 26 | import org.slf4j.LoggerFactory;
|
@@ -66,18 +64,14 @@ private void configureLoggerContext(Path rootPath) {
|
66 | 64 | Path configPath = rootPath.resolve(LOG4J2_CONFIG_FILE).toAbsolutePath();
|
67 | 65 | File log4jConfig = configPath.toFile();
|
68 | 66 | 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); |
76 | 70 | } else {
|
77 | 71 | log.warn("log4j2.xml not found for {}", getClass().getName());
|
78 | 72 | }
|
79 | 73 | } 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); |
81 | 75 | }
|
82 | 76 | }
|
83 | 77 |
|
|
0 commit comments