This is an automated email from the ASF dual-hosted git repository.
shunzhang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bifromq.git
The following commit(s) were added to refs/heads/main by this push:
new 1fce264d update archetype: reconfigure plugin's log context correctly
(#146)
1fce264d is described below
commit 1fce264d2079b03a38bbb0f8492ed061cb3c9032
Author: Yonny(Yu) Hao <[email protected]>
AuthorDate: Tue Jun 17 13:52:46 2025 +0800
update archetype: reconfigure plugin's log context correctly (#146)
---
.../plugin-build/src/main/java/__pluginName__.java | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git
a/bifromq-plugin/bifromq-plugin-archetype/src/main/resources/archetype-resources/plugin-build/src/main/java/__pluginName__.java
b/bifromq-plugin/bifromq-plugin-archetype/src/main/resources/archetype-resources/plugin-build/src/main/java/__pluginName__.java
index 7f374255..fa332465 100644
---
a/bifromq-plugin/bifromq-plugin-archetype/src/main/resources/archetype-resources/plugin-build/src/main/java/__pluginName__.java
+++
b/bifromq-plugin/bifromq-plugin-archetype/src/main/resources/archetype-resources/plugin-build/src/main/java/__pluginName__.java
@@ -21,8 +21,6 @@ package ${package};
import org.apache.bifromq.plugin.BifroMQPlugin;
import org.apache.bifromq.plugin.BifroMQPluginDescriptor;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,18 +64,14 @@ public class ${pluginName} extends
BifroMQPlugin<${pluginContextName}> {
Path configPath =
rootPath.resolve(LOG4J2_CONFIG_FILE).toAbsolutePath();
File log4jConfig = configPath.toFile();
if (log4jConfig.exists()) {
- // Shutdown any existing context to avoid resource leaks
- LoggerContext ctx = (LoggerContext)
LogManager.getContext(false);
- ctx.stop();
-
- // Initialize a new LoggerContext with the plugin-specific
configuration
- Configurator.initialize(null, configPath.toString());
- log.info("Loaded Log4j2 configuration from {}", configPath);
+ // reconfigure Log4j2 with the plugin-specific configuration
+ Configurator.reconfigure(log4jConfig.toURI());
+ log.info("Loaded Log4j configuration from {}", configPath);
} else {
log.warn("log4j2.xml not found for {}", getClass().getName());
}
} catch (Exception e) {
- log.error("Failed to configure Log4j2 for {}",
getClass().getName(), e);
+ log.error("Failed to configure Log4j for {}",
getClass().getName(), e);
}
}