mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve stack feature for package gdebug/gerror
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"io"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -24,7 +25,8 @@ type Error struct {
|
||||
}
|
||||
|
||||
const (
|
||||
stackFilterKey = "/errors/gerror/gerror"
|
||||
// Filtering key for current error module paths.
|
||||
stackFilterKeyLocal = "/errors/gerror/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -182,20 +184,34 @@ func formatSubStack(st stack, buffer *bytes.Buffer) {
|
||||
for _, p := range st {
|
||||
if fn := runtime.FuncForPC(p - 1); fn != nil {
|
||||
file, line := fn.FileLine(p - 1)
|
||||
if strings.Contains(file, stackFilterKey) {
|
||||
continue
|
||||
// Custom filtering.
|
||||
if !utils.IsDebugEnabled() {
|
||||
if strings.Contains(file, utils.StackFilterKeyForGoFrame) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(file, stackFilterKeyLocal) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// Avoid stack string like "<autogenerated>"
|
||||
if strings.Contains(file, "<") {
|
||||
continue
|
||||
}
|
||||
if goRootForFilter != "" && len(file) >= len(goRootForFilter) && file[0:len(goRootForFilter)] == goRootForFilter {
|
||||
// Ignore GO ROOT paths.
|
||||
if goRootForFilter != "" &&
|
||||
len(file) >= len(goRootForFilter) &&
|
||||
file[0:len(goRootForFilter)] == goRootForFilter {
|
||||
continue
|
||||
}
|
||||
// Graceful indent.
|
||||
if index > 9 {
|
||||
space = " "
|
||||
}
|
||||
buffer.WriteString(fmt.Sprintf(" %d).%s%s\n \t%s:%d\n", index, space, fn.Name(), file, line))
|
||||
buffer.WriteString(fmt.Sprintf(
|
||||
" %d).%s%s\n \t%s:%d\n",
|
||||
index, space, fn.Name(), file, line,
|
||||
))
|
||||
index++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user