add stack filter of goframe module path for logging content

This commit is contained in:
John Guo
2021-12-10 18:52:35 +08:00
parent e02bdd875d
commit 39bbca2a50
8 changed files with 29 additions and 23 deletions

View File

@ -45,14 +45,14 @@ func init() {
// Caller returns the function name and the absolute file path along with its line
// number of the caller.
func Caller(skip ...int) (function string, path string, line int) {
return CallerWithFilter("", skip...)
return CallerWithFilter(nil, skip...)
}
// CallerWithFilter returns the function name and the absolute file path along with
// its line number of the caller.
//
// The parameter `filter` is used to filter the path of the caller.
func CallerWithFilter(filter string, skip ...int) (function string, path string, line int) {
// The parameter `filters` is used to filter the path of the caller.
func CallerWithFilter(filters []string, skip ...int) (function string, path string, line int) {
var (
number = 0
ok = true
@ -60,7 +60,7 @@ func CallerWithFilter(filter string, skip ...int) (function string, path string,
if len(skip) > 0 {
number = skip[0]
}
pc, file, line, start := callerFromIndex([]string{filter})
pc, file, line, start := callerFromIndex(filters)
if start != -1 {
for i := start + number; i < maxCallerDepth; i++ {
if i != start {

View File

@ -23,15 +23,15 @@ 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(nil, skip...)
}
// StackWithFilter 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.
//
// The parameter `filter` is used to filter the path of the caller.
func StackWithFilter(filter string, skip ...int) string {
return StackWithFilters([]string{filter}, skip...)
func StackWithFilter(filters []string, skip ...int) string {
return StackWithFilters(filters, skip...)
}
// StackWithFilters returns a formatted stack trace of the goroutine that calls it.