mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
新增Stack等级日志
This commit is contained in:
16
log/log.go
16
log/log.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -18,7 +19,8 @@ const (
|
|||||||
releaseLevel = 1
|
releaseLevel = 1
|
||||||
warningLevel = 2
|
warningLevel = 2
|
||||||
errorLevel = 3
|
errorLevel = 3
|
||||||
fatalLevel = 4
|
stackLevel = 4
|
||||||
|
fatalLevel = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -26,6 +28,7 @@ const (
|
|||||||
printReleaseLevel = "[release] "
|
printReleaseLevel = "[release] "
|
||||||
printWarningLevel = "[warning] "
|
printWarningLevel = "[warning] "
|
||||||
printErrorLevel = "[error ] "
|
printErrorLevel = "[error ] "
|
||||||
|
printStackLevel = "[stack ] "
|
||||||
printFatalLevel = "[fatal ] "
|
printFatalLevel = "[fatal ] "
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,6 +54,8 @@ func New(strLevel string, pathname string, flag int) (*Logger, error) {
|
|||||||
level = warningLevel
|
level = warningLevel
|
||||||
case "error":
|
case "error":
|
||||||
level = errorLevel
|
level = errorLevel
|
||||||
|
case "stack":
|
||||||
|
level = stackLevel
|
||||||
case "fatal":
|
case "fatal":
|
||||||
level = fatalLevel
|
level = fatalLevel
|
||||||
default:
|
default:
|
||||||
@@ -159,6 +164,10 @@ func (logger *Logger) Error(format string, a ...interface{}) {
|
|||||||
logger.doPrintf(errorLevel, printErrorLevel, format, a...)
|
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{}) {
|
func (logger *Logger) Fatal(format string, a ...interface{}) {
|
||||||
logger.doPrintf(fatalLevel, printFatalLevel, format, a...)
|
logger.doPrintf(fatalLevel, printFatalLevel, format, a...)
|
||||||
}
|
}
|
||||||
@@ -188,6 +197,11 @@ func Error(format string, a ...interface{}) {
|
|||||||
gLogger.doPrintf(errorLevel, printErrorLevel, format, a...)
|
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{}) {
|
func Fatal(format string, a ...interface{}) {
|
||||||
gLogger.doPrintf(fatalLevel, printFatalLevel, format, a...)
|
gLogger.doPrintf(fatalLevel, printFatalLevel, format, a...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user