1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
util.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-09-16 19:06 . feat: rebuild log
package log
//const (
// maximumCallerDepth int = 25
// knownLoggingFrames int = 4
//)
//var (
// callerInitOnce sync.Once
// loggerPackage string
// minimumCallerDepth int
//)
//func getCaller() *runtime.Frame {
// // cache this package's fully-qualified name
// callerInitOnce.Do(func() {
// pcs := make([]uintptr, maximumCallerDepth)
// _ = runtime.Callers(0, pcs)
//
// // dynamic get the package name and the minimum caller depth
// for i := 0; i < maximumCallerDepth; i++ {
// funcName := runtime.FuncForPC(pcs[i]).Name()
// if strings.Contains(funcName, "getCaller") {
// loggerPackage = getPackageName(funcName)
// break
// }
// }
//
// minimumCallerDepth = knownLoggingFrames
// })
//
// // Restrict the lookback frames to avoid runaway lookups
// pcs := make([]uintptr, maximumCallerDepth)
// depth := runtime.Callers(minimumCallerDepth, pcs)
// frames := runtime.CallersFrames(pcs[:depth])
//
// for f, again := frames.Next(); again; f, again = frames.Next() {
// pkg := getPackageName(f.Function)
//
// // If the caller isn't part of this package, we're done
// if pkg != loggerPackage {
// return &f //nolint:scopelint
// }
// }
//
// // if we got here, we failed to find the caller's context
// return nil
//}
//
//func getPackageName(f string) string {
// for {
// lastPeriod := strings.LastIndex(f, ".")
// lastSlash := strings.LastIndex(f, "/")
// if lastPeriod > lastSlash {
// f = f[:lastPeriod]
// } else {
// break
// }
// }
// return f
//}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.3.9

搜索帮助