From 0ccb1d5555ca91a82c2cbe3ed0ca331391ba2067 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Sun, 24 Apr 2022 16:54:05 +0800 Subject: [PATCH] [Improvement] not print logs to fe.out when fe is running under daemon mode --- be/src/common/status.h | 2 +- bin/start_fe.sh | 1 + .../src/main/java/org/apache/doris/PaloFe.java | 3 +++ .../java/org/apache/doris/common/Log4jConfig.java | 14 +++++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/be/src/common/status.h b/be/src/common/status.h index ad884cee5ed4ce..1ebbd913e33f76 100644 --- a/be/src/common/status.h +++ b/be/src/common/status.h @@ -22,7 +22,7 @@ namespace doris { // ErrorName, ErrorCode, String Description, Should print stacktrace #define APPLY_FOR_ERROR_CODES(M) \ - M(OLAP_SUCCESS, 0, "", true) \ + M(OLAP_SUCCESS, 0, "", false) \ M(OLAP_ERR_OTHER_ERROR, -1, "", true) \ M(OLAP_REQUEST_FAILED, -2, "", true) \ M(OLAP_ERR_OS_ERROR, -100, "", true) \ diff --git a/bin/start_fe.sh b/bin/start_fe.sh index 009448d2bc6231..02620f2e6b8660 100755 --- a/bin/start_fe.sh +++ b/bin/start_fe.sh @@ -180,6 +180,7 @@ if [ ${IMAGE_TOOL} -eq 1 ]; then elif [ ${RUN_DAEMON} -eq 1 ]; then nohup $LIMIT $JAVA $final_java_opt org.apache.doris.PaloFe ${HELPER} "$@" >> $LOG_DIR/fe.out 2>&1 < /dev/null & else + export DORIS_LOG_TO_STDERR=1 $LIMIT $JAVA $final_java_opt org.apache.doris.PaloFe ${HELPER} "$@" < /dev/null fi diff --git a/fe/fe-core/src/main/java/org/apache/doris/PaloFe.java b/fe/fe-core/src/main/java/org/apache/doris/PaloFe.java index 0a1fb68c49f0ef..9c171404e322c8 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/PaloFe.java +++ b/fe/fe-core/src/main/java/org/apache/doris/PaloFe.java @@ -66,6 +66,9 @@ public static void main(String[] args) { // entrance for doris frontend public static void start(String dorisHomeDir, String pidDir, String[] args) { + if (System.getenv("DORIS_LOG_TO_STDERR") != null) { + Log4jConfig.foreground = true; + } if (Strings.isNullOrEmpty(dorisHomeDir)) { System.err.println("env DORIS_HOME is not set."); return; 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 470636cb5d3f54..7f65abe5f73983 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 @@ -97,7 +97,7 @@ public class Log4jConfig extends XmlConfiguration { " \n" + " \n" + " \n" + - " \n" + + " \n" + " \n" + " \n" + " \n" + @@ -116,6 +116,12 @@ public class Log4jConfig extends XmlConfiguration { public static String confDir; // custom conf dir public static String customConfDir; + // Doris uses both system.out and log4j to print log messages. + // This variable is used to check whether to add console appender to loggers. + // If doris is running under daemon mode, then this variable == false, and console logger will not be added. + // If doris is not running under daemon mode, then this variable == true, and console logger will be added to + // loggers, all logs will be printed to console. + public static boolean foreground = false; private static void reconfig() throws IOException { String newXmlConfTemplate = xmlConfTemplate; @@ -167,6 +173,12 @@ private static void reconfig() throws IOException { newXmlConfTemplate = newXmlConfTemplate.replaceAll("", sb.toString()); + if (foreground) { + StringBuilder consoleLogger = new StringBuilder(); + consoleLogger.append("\n"); + newXmlConfTemplate = newXmlConfTemplate.replaceAll("", + consoleLogger.toString()); + } Map properties = Maps.newHashMap(); properties.put("sys_log_dir", sysLogDir); properties.put("sys_file_pattern", sysLogRollPattern);