fix issue in invalid error stacks for glog; improve internal/debug and gutil for stack printing

This commit is contained in:
John
2019-08-08 22:58:49 +08:00
parent 4eac97a7d8
commit 7172ae0232
4 changed files with 16 additions and 19 deletions

View File

@ -1,7 +1,10 @@
package main
func main() {
for i := 0; i < 10; i++ {
import (
"github.com/gogf/gf/os/glog"
)
}
func main() {
glog.Error("error")
glog.Errorfln("error")
}

View File

@ -39,7 +39,7 @@ func PrintStack(skip ...int) {
// Stack returns a formatted stack trace of the goroutine that calls it.
// It calls runtime.Stack with a large enough buffer to capture the entire trace.
func Stack(skip ...int) string {
return StackWithFilter("", skip...)
return StackWithFilter(gFILTER_KEY, skip...)
}
// StackWithFilter returns a formatted stack trace of the goroutine that calls it.

View File

@ -349,9 +349,5 @@ func (l *Logger) PrintStack(skip ...int) {
// GetStack returns the caller stack content,
// the optional parameter <skip> specify the skipped stack offset from the end point.
func (l *Logger) GetStack(skip ...int) string {
number := 1
if len(skip) > 0 {
number = skip[0] + 1
}
return debug.StackWithFilter(gPATH_FILTER_KEY, number)
return debug.StackWithFilter(gPATH_FILTER_KEY, skip...)
}

View File

@ -7,24 +7,22 @@
package gutil
import (
"fmt"
"github.com/gogf/gf/internal/debug"
)
const (
gFILTER_KEY = "/gf/util/gutil/gutil_debug.go"
)
// PrintStack prints to standard error the stack trace returned by runtime.Stack.
func PrintStack(skip ...int) {
number := 1
if len(skip) > 0 {
number = skip[0] + 1
}
debug.PrintStack(number)
fmt.Print(Stack(skip...))
}
// Stack returns a formatted stack trace of the goroutine that calls it.
// It calls runtime.Stack with a large enough buffer to capture the entire trace.
func Stack(skip ...int) string {
number := 1
if len(skip) > 0 {
number = skip[0] + 1
}
return debug.Stack(number)
return debug.StackWithFilter(gFILTER_KEY, skip...)
}