新增Stack等级日志

This commit is contained in:
boyce
2021-01-20 11:16:16 +08:00
parent 3c5c424996
commit 2679e8a2bf

View File

@@ -6,6 +6,7 @@ import (
"log"
"os"
"path"
"runtime/debug"
"strings"
"time"
)
@@ -18,7 +19,8 @@ const (
releaseLevel = 1
warningLevel = 2
errorLevel = 3
fatalLevel = 4
stackLevel = 4
fatalLevel = 5
)
const (
@@ -26,6 +28,7 @@ const (
printReleaseLevel = "[release] "
printWarningLevel = "[warning] "
printErrorLevel = "[error ] "
printStackLevel = "[stack ] "
printFatalLevel = "[fatal ] "
)
@@ -51,6 +54,8 @@ func New(strLevel string, pathname string, flag int) (*Logger, error) {
level = warningLevel
case "error":
level = errorLevel
case "stack":
level = stackLevel
case "fatal":
level = fatalLevel
default:
@@ -159,6 +164,10 @@ func (logger *Logger) Error(format string, a ...interface{}) {
logger.doPrintf(errorLevel, printErrorLevel, format, a...)
}
func (logger *Logger) Stack(format string, a ...interface{}) {
logger.doPrintf(stackLevel, printStackLevel, format, a...)
}
func (logger *Logger) Fatal(format string, a ...interface{}) {
logger.doPrintf(fatalLevel, printFatalLevel, format, a...)
}
@@ -188,6 +197,11 @@ func Error(format string, a ...interface{}) {
gLogger.doPrintf(errorLevel, printErrorLevel, format, a...)
}
func Stack(format string, a ...interface{}) {
s := string(debug.Stack())
gLogger.doPrintf(stackLevel, printStackLevel, s+"\n"+format, a...)
}
func Fatal(format string, a ...interface{}) {
gLogger.doPrintf(fatalLevel, printFatalLevel, format, a...)
}