mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
add switch of brief stack for package gerror (#2153)
This commit is contained in:
@ -13,6 +13,7 @@ package gerror
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/internal/command"
|
||||
)
|
||||
|
||||
// IIs is the interface for Is feature.
|
||||
@ -56,3 +57,20 @@ type IUnwrap interface {
|
||||
Error() string
|
||||
Unwrap() error
|
||||
}
|
||||
|
||||
const (
|
||||
// commandEnvKeyForBrief is the command environment name for switch key for brief error stack.
|
||||
commandEnvKeyForBrief = "gf.gerror.brief"
|
||||
)
|
||||
|
||||
var (
|
||||
// isUsingBriefStack is the switch key for brief error stack.
|
||||
isUsingBriefStack bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
value := command.GetOptWithEnv(commandEnvKeyForBrief)
|
||||
if value == "1" || value == "true" {
|
||||
isUsingBriefStack = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ type stack []uintptr
|
||||
|
||||
const (
|
||||
// maxStackDepth marks the max stack depth for error back traces.
|
||||
maxStackDepth = 32
|
||||
maxStackDepth = 64
|
||||
)
|
||||
|
||||
// Cause returns the root cause error of `err`.
|
||||
|
||||
@ -12,6 +12,8 @@ import (
|
||||
"io"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/consts"
|
||||
)
|
||||
|
||||
// Format formats the frame according to the fmt.Formatter interface.
|
||||
@ -52,9 +54,16 @@ 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)
|
||||
// Custom filtering.
|
||||
if strings.Contains(file, stackFilterKeyLocal) {
|
||||
continue
|
||||
if isUsingBriefStack {
|
||||
// filter whole GoFrame packages stack paths.
|
||||
if strings.Contains(file, consts.StackFilterKeyForGoFrame) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
// package path stack filtering.
|
||||
if strings.Contains(file, stackFilterKeyLocal) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// Avoid stack string like "`autogenerated`"
|
||||
if strings.Contains(file, "<") {
|
||||
|
||||
Reference in New Issue
Block a user