自定义日志深度

This commit is contained in:
boyce
2019-03-06 12:41:32 +08:00
parent 3e5a288de7
commit c22c193e70
2 changed files with 12 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ type LogModule struct {
logFile *os.File
openLevel uint
locker sync.Mutex
calldepth int
}
func (slf *LogModule) GetCurrentFileName() string {
@@ -77,6 +78,7 @@ func (slf *LogModule) Init(logfilename string, openLevel uint) {
slf.currentDay = 0
slf.logfilename = logfilename
slf.openLevel = openLevel
slf.calldepth = 3
}
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.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{}) {
@@ -101,5 +103,9 @@ func (slf *LogModule) Print(level uint, v ...interface{}) {
}
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
}

View File

@@ -23,3 +23,7 @@ func (slf *LogService) Printf(level uint, format string, v ...interface{}) {
func (slf *LogService) Print(level uint, v ...interface{}) {
slf.logmodule.Print(level, v...)
}
func (slf *LogService) AppendCallDepth(calldepth int) {
slf.logmodule.AppendCallDepth(calldepth)
}