Skip to content

Commit b20f36a

Browse files
committed
Add extra info in stack info
1 parent 5f1f942 commit b20f36a

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

logging.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,37 @@ func TimeTrack(start time.Time, name string) {
143143

144144
// LogFunctionStart log function start if debug is enabled
145145
func LogFunctionStart() {
146+
LogFunctionStarts("")
147+
}
148+
149+
// LogFunctionStart log function start if debug is enabled
150+
func LogFunctionStarts(info string) {
146151
if !debugEnabled {
147152
return
148153
}
149154
pc, _, _, ok := runtime.Caller(1)
150155
details := runtime.FuncForPC(pc)
151156
if ok && details != nil {
152-
Log.Debugf("Entering %s())", details.Name())
157+
Log.Debugf("Entering %s()) %s", details.Name(), info)
153158
}
154159
}
155160

156161
// LogFunctionEnd log function end if debug is enabled
157162
// Usage: defer LogFunctionEnd(time.Now())
158163
func LogFunctionEnd(start time.Time) {
164+
LogFunctionEnds(start, "")
165+
}
166+
167+
// LogFunctionEnd log function end if debug is enabled
168+
// Usage: defer LogFunctionEnd(time.Now())
169+
func LogFunctionEnds(start time.Time, info string) {
159170
if !debugEnabled {
160171
return
161172
}
162173
pc, _, _, ok := runtime.Caller(1)
163174
details := runtime.FuncForPC(pc)
164175
if ok && details != nil {
165176
elapsed := time.Since(start)
166-
Log.Debugf("Leaving %s() tooks %s ms", details.Name(), elapsed)
177+
Log.Debugf("Leaving %s() %s tooks %s ms", details.Name(), info, elapsed)
167178
}
168179
}

logging_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ func stack2() {
187187
}
188188

189189
func stack3() {
190-
LogFunctionStart()
190+
LogFunctionStarts("stack3")
191191
Log.Debugf("In stack3")
192-
defer LogFunctionEnd(time.Now())
193-
192+
defer LogFunctionEnds(time.Now(), "stack3")
194193
}

0 commit comments

Comments
 (0)