From eec8fe18e4fbc841f75dbc03969e4e7c6b80d87b Mon Sep 17 00:00:00 2001 From: bryan Date: Thu, 29 May 2025 13:00:39 +0800 Subject: [PATCH] [DEV] fatal exit 1 --- log.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/log.go b/log.go index 60395ee..88facb5 100644 --- a/log.go +++ b/log.go @@ -227,13 +227,18 @@ func (log *Logger) logwrite(typ LogLevel, calldepth int, format string, v ...int log.golog.SetPrefix("\x1b[33m" + "UNKN " + header + "\x1b[0m" + " ") } - if typ == FATAL || typ == WARNING || typ == ERROR { + if typ == WARNING || typ == ERROR { log.golog.Output(calldepth, "\x1b[31m"+fmt.Sprintf(format, v...)+"\x1b[0m") } else if typ == INFO || typ == DEBUG { log.golog.Output(calldepth, fmt.Sprintf(format, v...)) } else if typ == NOTICE { calldepth = calldepth + 2 log.golog.Output(calldepth, fmt.Sprintf(format, v...)) + } else if typ == FATAL { + stackstr := strings.Replace(string(debug.Stack()), "\n", "\n== ", -1) + stackstr = "\n== Fatal stack:\n" + str.SkipLine(stackstr, calldepth*2+1) + log.golog.Output(calldepth, fmt.Sprintf(format, v...)+stackstr) + os.Exit(1) } else if typ == PANIC { stackstr := strings.Replace(string(debug.Stack()), "\n", "\n== ", -1) stackstr = "\n== Panic stack:\n" + str.SkipLine(stackstr, calldepth*2+1)