mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix issue in invalid error stacks for glog; improve internal/debug and gutil for stack printing
This commit is contained in:
@ -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")
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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...)
|
||||
}
|
||||
|
||||
@ -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...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user