1 Star 1 Fork 0

凡卡/utils

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
goroutine.go 804 Bytes
一键复制 编辑 原始数据 按行查看 历史
凡卡 提交于 2024-08-12 13:57 +08:00 . 添加了日志库,整数转字节改为大端序
package utils
import (
"runtime"
)
func Go(f func()) {
go func() {
defer PrintPanicStack()
f()
}()
}
/*
错误处理
*/
func PrintPanicStack() {
if x := recover(); x != nil {
//fmt.Println(x)
for i := 0; i < 10; i++ {
funcName, file, line, ok := runtime.Caller(i)
if ok {
// fmt.Println("frame :[func:%s,file:%s,line:%d]\n", i, runtime.FuncForPC(funcName).Name(), file, line)
Log.Error().Int("n", i).Str("func", runtime.FuncForPC(funcName).Name()).Str("file", file).Int("line", line).Send()
//Log.Error("%d frame :[func:%s,file:%s,line:%d]\n", i, runtime.FuncForPC(funcName).Name(), file, line)
//Log.Error().
// fmt.Println("frame " + strconv.Itoa(i) + ":[func:" + runtime.FuncForPC(funcName).Name() + ",file:" + file + ",line:" + line + "]\n")
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/prestonTao/utils.git
git@gitee.com:prestonTao/utils.git
prestonTao
utils
utils
ff2eb0330898

搜索帮助