mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve error stack configuration for package gerror, add framework error stack filter for package glog (#2918)
This commit is contained in:
@ -13,7 +13,6 @@ package gerror
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/internal/command"
|
||||
)
|
||||
|
||||
// IIs is the interface for Is feature.
|
||||
@ -59,21 +58,6 @@ type IUnwrap interface {
|
||||
}
|
||||
|
||||
const (
|
||||
// commandEnvKeyForBrief is the command environment name for switch key for brief error stack.
|
||||
commandEnvKeyForBrief = "gf.gerror.brief"
|
||||
|
||||
// commaSeparatorSpace is the comma separator with space.
|
||||
commaSeparatorSpace = ", "
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/consts"
|
||||
"github.com/gogf/gf/v2/internal/errors"
|
||||
)
|
||||
|
||||
// stackInfo manages stack info of certain error.
|
||||
@ -35,9 +36,10 @@ func (err *Error) Stack() string {
|
||||
return ""
|
||||
}
|
||||
var (
|
||||
loop = err
|
||||
index = 1
|
||||
infos []*stackInfo
|
||||
loop = err
|
||||
index = 1
|
||||
infos []*stackInfo
|
||||
isStackModeBrief = errors.IsStackModeBrief()
|
||||
)
|
||||
for loop != nil {
|
||||
info := &stackInfo{
|
||||
@ -46,7 +48,7 @@ func (err *Error) Stack() string {
|
||||
}
|
||||
index++
|
||||
infos = append(infos, info)
|
||||
loopLinesOfStackInfo(loop.stack, info)
|
||||
loopLinesOfStackInfo(loop.stack, info, isStackModeBrief)
|
||||
if loop.error != nil {
|
||||
if e, ok := loop.error.(*Error); ok {
|
||||
loop = e
|
||||
@ -131,14 +133,14 @@ func formatStackLines(buffer *bytes.Buffer, lines *list.List) string {
|
||||
}
|
||||
|
||||
// loopLinesOfStackInfo iterates the stack info lines and produces the stack line info.
|
||||
func loopLinesOfStackInfo(st stack, info *stackInfo) {
|
||||
func loopLinesOfStackInfo(st stack, info *stackInfo, isStackModeBrief bool) {
|
||||
if st == nil {
|
||||
return
|
||||
}
|
||||
for _, p := range st {
|
||||
if fn := runtime.FuncForPC(p - 1); fn != nil {
|
||||
file, line := fn.FileLine(p - 1)
|
||||
if isUsingBriefStack {
|
||||
if isStackModeBrief {
|
||||
// filter whole GoFrame packages stack paths.
|
||||
if strings.Contains(file, consts.StackFilterKeyForGoFrame) {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user