mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 03:05:05 +08:00
add switch of brief stack for package gerror
(#2153)
This commit is contained in:
parent
141ca62c6d
commit
66aa0c7050
@ -33,11 +33,8 @@ func (m *Model) QuoteWord(s string) string {
|
||||
func (m *Model) TableFields(tableStr string, schema ...string) (fields map[string]*TableField, err error) {
|
||||
var (
|
||||
table = m.db.GetCore().guessPrimaryTableName(tableStr)
|
||||
usedSchema = m.schema
|
||||
usedSchema = gutil.GetOrDefaultStr(m.schema, schema...)
|
||||
)
|
||||
if len(schema) > 0 && schema[0] != "" {
|
||||
usedSchema = schema[0]
|
||||
}
|
||||
return m.db.TableFields(m.GetCtx(), table, usedSchema)
|
||||
}
|
||||
|
||||
|
@ -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, "<") {
|
||||
|
@ -14,4 +14,8 @@ const (
|
||||
ConfigNodeNameViewer = "viewer"
|
||||
ConfigNodeNameServer = "server" // General version configuration item name.
|
||||
ConfigNodeNameServerSecondary = "httpserver" // New version configuration item name support from v2.
|
||||
|
||||
// StackFilterKeyForGoFrame is the stack filtering key for all GoFrame module paths.
|
||||
// Eg: .../pkg/mod/github.com/gogf/gf/v2@v2.0.0-20211011134327-54dd11f51122/debug/gdebug/gdebug_caller.go
|
||||
StackFilterKeyForGoFrame = "github.com/gogf/gf/"
|
||||
)
|
||||
|
@ -13,10 +13,6 @@ import (
|
||||
const (
|
||||
// Debug key for checking if in debug mode.
|
||||
commandEnvKeyForDebugKey = "gf.debug"
|
||||
|
||||
// StackFilterKeyForGoFrame is the stack filtering key for all GoFrame module paths.
|
||||
// Eg: .../pkg/mod/github.com/gogf/gf/v2@v2.0.0-20211011134327-54dd11f51122/debug/gdebug/gdebug_caller.go
|
||||
StackFilterKeyForGoFrame = "github.com/gogf/gf/"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/internal/consts"
|
||||
"github.com/gogf/gf/v2/net/goai"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
@ -88,7 +88,7 @@ func (s *Server) setHandler(ctx context.Context, in setHandlerInput) {
|
||||
}
|
||||
handler.Id = handlerIdGenerator.Add(1)
|
||||
if handler.Source == "" {
|
||||
_, file, line := gdebug.CallerWithFilter([]string{utils.StackFilterKeyForGoFrame})
|
||||
_, file, line := gdebug.CallerWithFilter([]string{consts.StackFilterKeyForGoFrame})
|
||||
handler.Source = fmt.Sprintf(`%s:%d`, file, line)
|
||||
}
|
||||
domain, method, uri, err := s.parsePattern(pattern)
|
||||
|
@ -12,8 +12,8 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/internal/consts"
|
||||
"github.com/gogf/gf/v2/internal/reflection"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@ -263,7 +263,7 @@ func (g *RouterGroup) Middleware(handlers ...HandlerFunc) *RouterGroup {
|
||||
|
||||
// preBindToLocalArray adds the route registering parameters to an internal variable array for lazily registering feature.
|
||||
func (g *RouterGroup) preBindToLocalArray(bindType string, pattern string, object interface{}, params ...interface{}) *RouterGroup {
|
||||
_, file, line := gdebug.CallerWithFilter([]string{utils.StackFilterKeyForGoFrame})
|
||||
_, file, line := gdebug.CallerWithFilter([]string{consts.StackFilterKeyForGoFrame})
|
||||
preBindItems = append(preBindItems, &preBindItem{
|
||||
group: g,
|
||||
bindType: bindType,
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/internal/consts"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
@ -163,7 +163,7 @@ func (l *Logger) print(ctx context.Context, level int, stack string, values ...i
|
||||
// Caller path and Fn name.
|
||||
if l.config.Flags&(F_FILE_LONG|F_FILE_SHORT|F_CALLER_FN) > 0 {
|
||||
callerFnName, path, line := gdebug.CallerWithFilter(
|
||||
[]string{utils.StackFilterKeyForGoFrame},
|
||||
[]string{consts.StackFilterKeyForGoFrame},
|
||||
l.config.StSkip,
|
||||
)
|
||||
if l.config.Flags&F_CALLER_FN > 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user