You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by kx...@apache.org on 2023/10/11 16:55:35 UTC
[doris] 18/47: [Enhancement](log) Improve Safety and Robustness of Log4j Configuration (#24861)
This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
commit c471d3589bc9f956c75fde6ae06240809d516836
Author: zy-kkk <zh...@gmail.com>
AuthorDate: Mon Oct 9 06:44:37 2023 -0500
[Enhancement](log) Improve Safety and Robustness of Log4j Configuration (#24861)
---
.../java/org/apache/doris/common/Log4jConfig.java | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/Log4jConfig.java b/fe/fe-core/src/main/java/org/apache/doris/common/Log4jConfig.java
index 019886ec648..3c72048e00b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/Log4jConfig.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/Log4jConfig.java
@@ -29,6 +29,7 @@ import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
//
@@ -228,12 +229,20 @@ public class Log4jConfig extends XmlConfiguration {
SpringLog4j2Config.writeSpringLogConf(customConfDir);
// new SimpleLog4jConfiguration with xmlConfTemplate
- ByteArrayInputStream bis = new ByteArrayInputStream(newXmlConfTemplate.getBytes("UTF-8"));
- ConfigurationSource source = new ConfigurationSource(bis);
- Log4jConfig config = new Log4jConfig(source);
+ if (newXmlConfTemplate == null || newXmlConfTemplate.isEmpty()) {
+ throw new IOException("The configuration template is empty!");
+ }
+
+ Log4jConfig config;
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(newXmlConfTemplate.getBytes(StandardCharsets.UTF_8))) {
+ ConfigurationSource source = new ConfigurationSource(bis);
+ config = new Log4jConfig(source);
- LoggerContext context = (LoggerContext) LogManager.getContext(false);
- context.start(config);
+ LoggerContext context = (LoggerContext) LogManager.getContext(LogManager.class.getClassLoader(), false);
+ context.start(config);
+ } catch (Exception e) {
+ throw new IOException("Error occurred while configuring Log4j", e);
+ }
}
public static String getLogXmlConfTemplate() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org