浏览代码

更新退出代码并增强日志检查

增加了新的退出代码`exitCodeErrorLogMustBeReady`,并在多个函数中添加了对日志是否准备好的检查。如果日志未准备好,则抛出异常并返回特定的退出代码。同时,调整了成功退出时的日志级别从错误改为警告。
SongZihuan 2 周之前
父节点
当前提交
2180817743
共有 2 个文件被更改,包括 16 次插入4 次删除
  1. 1 0
      CHANGELOG.md
  2. 15 4
      src/utils/exitutils/exit.go

+ 1 - 0
CHANGELOG.md

@@ -27,6 +27,7 @@
 - 修复无法读取`tag`对应`commit`值的漏洞。
 - 修复`Output Config File`逻辑判断错误
 - 修复设置`SigQuitExit`默认动作的错误
+- 修复了退出日志的日志等级
 
 ### 重构
 

+ 15 - 4
src/utils/exitutils/exit.go

@@ -10,8 +10,9 @@ import (
 )
 
 const (
-	exitCodeMin = 0
-	exitCodeMax = 255
+	exitCodeMin                 = 0
+	exitCodeMax                 = 255
+	exitCodeErrorLogMustBeReady = 254
 )
 
 func getExitCode(defaultExitCode int, exitCode ...int) (ec int) {
@@ -46,6 +47,11 @@ func InitFailedErrorForLoggerModule(reason string, exitCode ...int) int {
 }
 
 func InitFailedError(module string, reason string, exitCode ...int) int {
+	if !logger.IsReady() {
+		panic("Logger must be ready!!!")
+		return exitCodeErrorLogMustBeReady
+	}
+
 	if reason == "" {
 		reason = "no reason"
 	}
@@ -59,6 +65,11 @@ func InitFailedError(module string, reason string, exitCode ...int) int {
 }
 
 func RunError(reason string, exitCode ...int) int {
+	if !logger.IsReady() {
+		panic("Logger must be ready!!!")
+		return exitCodeErrorLogMustBeReady
+	}
+
 	if reason == "" {
 		reason = "no reason"
 	}
@@ -74,7 +85,7 @@ func RunError(reason string, exitCode ...int) int {
 func SuccessExit(reason string, exitCode ...int) int {
 	if !logger.IsReady() {
 		panic("Logger must be ready!!!")
-		return -1
+		return exitCodeErrorLogMustBeReady
 	}
 
 	if reason == "" {
@@ -83,7 +94,7 @@ func SuccessExit(reason string, exitCode ...int) int {
 
 	ec := getExitCode(0, exitCode...)
 
-	logger.Errorf("Now we should exit with code %d (reason: %s) .", ec, reason)
+	logger.Warnf("Now we should exit with code %d (reason: %s) .", ec, reason)
 
 	return ec
 }