Browse Source

feat: 修改FATAL和SEND_ERROR的行为

FATAL_ERROR 强制退出
SEND_ERROR 强制跳转
SongZihuan 3 năm trước cách đây
mục cha
commit
67d8bc18e5
6 tập tin đã thay đổi với 14 bổ sung32 xóa
  1. 0 2
      include/core/core_init.h
  2. 0 2
      include/tool/log.h
  3. 0 4
      src/core/core_init.c
  4. 0 2
      src/main.c
  5. 0 2
      src/runtime/aFunlang.c
  6. 14 20
      src/tool/log.c

+ 0 - 2
include/core/core_init.h

@@ -9,8 +9,6 @@ typedef struct aFunCoreInitInfo aFunCoreInitInfo;
 struct aFunCoreInitInfo {
     char *base_dir;
 
-    bool fe;
-    bool se;
     jmp_buf *buf;
     LogLevel level;
 };

+ 0 - 2
include/tool/log.h

@@ -26,8 +26,6 @@ typedef enum LogFactoryPrintConsole LogFactoryPrintConsole;
 struct Logger {
     char *id;
     LogLevel level;
-    bool process_send_error;  // 若为false则send_error转换为error
-    bool process_fatal_error;  // 若为false则fatal_error转换为error
     jmp_buf *buf;
     int exit_type;    // 0-abort 其他值则为exit
 };

+ 0 - 4
src/core/core_init.c

@@ -23,8 +23,6 @@ static void destructCoreExit(void) {
 bool aFunCoreInit(aFunCoreInitInfo *info) {
     if (info == NULL) {
         static aFunCoreInitInfo info_default = {.base_dir=".",
-                                                .fe=true,
-                                                .se=true,
                                                 .buf=NULL,
                                                 .level=log_info};
         info = &info_default;
@@ -48,8 +46,6 @@ bool aFunCoreInit(aFunCoreInitInfo *info) {
         return false;
 
     initLogger(aFunCoreLogger, "aFunlang-core", info->level);
-    aFunCoreLogger->process_send_error = info->fe;
-    aFunCoreLogger->process_fatal_error = info->se;
     aFunCoreLogger->buf = info->buf;
 
     writeDebugLog(aFunCoreLogger, "aFunCore init success");

+ 0 - 2
src/main.c

@@ -75,8 +75,6 @@ INIT_ERROR:
     }
 
     initLogger(aFunlangLogger, "aFunlang-exe", info.level);
-    aFunlangLogger->process_send_error = true;
-    aFunlangLogger->process_fatal_error = true;
     aFunlangLogger->buf = &main_buf;
     writeDebugLog(aFunlangLogger, "aFunlang-exe init success");
 

+ 0 - 2
src/runtime/aFunlang.c

@@ -19,8 +19,6 @@ bool aFunInit(aFunInitInfo *info) {
     }
 
     aFunCoreInitInfo core_info = {.base_dir=info->base_dir,
-                                  .fe=true,
-                                  .se=true,
                                   .buf=info->buf,
                                   .level=info->level};
 

+ 14 - 20
src/tool/log.c

@@ -93,8 +93,6 @@ int initLogSystem(FilePath path) {
     atexit(destructLogSystem_at_exit);
 
     initLogger(&(log_factory.sys_log), "SYSTEM", log_debug);  // 设置为 debug, 记录 success 信息
-    log_factory.sys_log.process_fatal_error = true;
-    log_factory.sys_log.process_send_error = false;
     writeDebugLog(NULL, "Log system init success");
     writeDebugLog(NULL, "Log .log size %lld", log_size);
     writeDebugLog(NULL, "Log .csv size %lld", csv_size);
@@ -259,16 +257,14 @@ int writeSendErrorLog_(Logger *logger, char *file, int line, char *func, char *f
 
     va_list ap;
     va_start(ap, format);
-    int re = writeLog_(logger, true, log_send_error, file, line, func, format, ap);
-    if (logger->process_send_error) {
-        jmp_buf *buf = logger->buf;
-        if (buf != NULL) {
-            initLogger(logger, NULL, 0);  // 清零
-            longjmp(*buf, 1);
-        } else
-            exit(EXIT_FAILURE);
-    }
-    return re;
+    jmp_buf *buf = logger->buf;
+
+    writeLog_(logger, true, log_send_error, file, line, func, format, ap);
+    if (buf != NULL) {
+        initLogger(logger, NULL, 0);  // 清零
+        longjmp(*buf, 1);
+    } else
+        exit(EXIT_FAILURE);
 }
 
 int writeFatalErrorLog_(Logger *logger, char *file, int line, char *func, int exit_code, char *format, ...) {
@@ -276,12 +272,10 @@ int writeFatalErrorLog_(Logger *logger, char *file, int line, char *func, int ex
 
     va_list ap;
     va_start(ap, format);
-    int re = writeLog_(logger, true, log_fatal_error, file, line, func, format, ap);
-    if (logger->process_fatal_error) {  // TODO-szh 去除该设定, 强制退出
-        if (logger->exit_type == 0)
-            abort();
-        else
-            exit(exit_code);
-    }
-    return re;
+    writeLog_(logger, true, log_fatal_error, file, line, func, format, ap);
+
+    if (logger->exit_type == 0)
+        abort();
+    else
+        exit(exit_code);
 }