mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-12 02:27:28 +08:00
自定义日志深度
This commit is contained in:
@@ -36,6 +36,7 @@ type LogModule struct {
|
|||||||
logFile *os.File
|
logFile *os.File
|
||||||
openLevel uint
|
openLevel uint
|
||||||
locker sync.Mutex
|
locker sync.Mutex
|
||||||
|
calldepth int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *LogModule) GetCurrentFileName() string {
|
func (slf *LogModule) GetCurrentFileName() string {
|
||||||
@@ -77,6 +78,7 @@ func (slf *LogModule) Init(logfilename string, openLevel uint) {
|
|||||||
slf.currentDay = 0
|
slf.currentDay = 0
|
||||||
slf.logfilename = logfilename
|
slf.logfilename = logfilename
|
||||||
slf.openLevel = openLevel
|
slf.openLevel = openLevel
|
||||||
|
slf.calldepth = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *LogModule) GetLoggerByLevel(level uint) *log.Logger {
|
func (slf *LogModule) GetLoggerByLevel(level uint) *log.Logger {
|
||||||
@@ -92,7 +94,7 @@ func (slf *LogModule) Printf(level uint, format string, v ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
slf.CheckAndGenFile()
|
slf.CheckAndGenFile()
|
||||||
slf.GetLoggerByLevel(level).Output(3, fmt.Sprintf(format, v...))
|
slf.GetLoggerByLevel(level).Output(slf.calldepth, fmt.Sprintf(format, v...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *LogModule) Print(level uint, v ...interface{}) {
|
func (slf *LogModule) Print(level uint, v ...interface{}) {
|
||||||
@@ -101,5 +103,9 @@ func (slf *LogModule) Print(level uint, v ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
slf.CheckAndGenFile()
|
slf.CheckAndGenFile()
|
||||||
slf.GetLoggerByLevel(level).Output(3, fmt.Sprint(v...))
|
slf.GetLoggerByLevel(level).Output(slf.calldepth, fmt.Sprint(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *LogModule) AppendCallDepth(calldepth int) {
|
||||||
|
slf.calldepth += calldepth
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,3 +23,7 @@ func (slf *LogService) Printf(level uint, format string, v ...interface{}) {
|
|||||||
func (slf *LogService) Print(level uint, v ...interface{}) {
|
func (slf *LogService) Print(level uint, v ...interface{}) {
|
||||||
slf.logmodule.Print(level, v...)
|
slf.logmodule.Print(level, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slf *LogService) AppendCallDepth(calldepth int) {
|
||||||
|
slf.logmodule.AppendCallDepth(calldepth)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user