diff --git a/.example/other/test.go b/.example/other/test.go index fe4220413..cdccd9b43 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -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") } diff --git a/internal/debug/debug.go b/internal/debug/debug.go index 53921498c..be894abb1 100644 --- a/internal/debug/debug.go +++ b/internal/debug/debug.go @@ -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. diff --git a/os/glog/glog_logger.go b/os/glog/glog_logger.go index 774f3876b..9fb0aba72 100644 --- a/os/glog/glog_logger.go +++ b/os/glog/glog_logger.go @@ -349,9 +349,5 @@ func (l *Logger) PrintStack(skip ...int) { // GetStack returns the caller stack content, // the optional parameter 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...) } diff --git a/util/gutil/gutil_debug.go b/util/gutil/gutil_debug.go index 3117900c0..52c1b5842 100644 --- a/util/gutil/gutil_debug.go +++ b/util/gutil/gutil_debug.go @@ -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...) }