[DEV] fatal exit 1

This commit is contained in:
bryan 2025-05-29 13:00:39 +08:00
parent 6174dd559e
commit eec8fe18e4

7
log.go
View File

@ -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)