This is an automated email from the ASF dual-hosted git repository.
zykkk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 400b9f2f97b [Enhancement](log) Improve Safety and Robustness of Log4j
Configuration (#24861)
400b9f2f97b is described below
commit 400b9f2f97badd458c324dbc4aa4f57ff2219e4b
Author: zy-kkk <[email protected]>
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: [email protected]
For additional commands, e-mail: [email protected]