当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
6 Star 9 Fork 1

wzshiming / ffmt
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
stack.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
wzshiming 提交于 2019-04-18 14:13 . Optimization of mark
package ffmt
import (
"fmt"
"os"
"path/filepath"
"runtime"
)
// MarkStackFull Output stack full
func MarkStackFull() {
for i := 1; ; i++ {
s := SmarkStackFunc(i)
if s == "" {
break
}
fmt.Println(s)
}
}
// MarkStack Output prefix stack line pos
func MarkStack(skip int, a ...interface{}) {
fmt.Println(append([]interface{}{SmarkStack(skip + 1)}, a...)...)
}
// Mark Output prefix current line position
func Mark(a ...interface{}) {
MarkStack(1, a...)
}
// Smark returns Output prefix current line position
func Smark(a ...interface{}) string {
return SmarkStack(1, a...)
}
var curDir, _ = os.Getwd()
func getRelativeDirectory(targpath string) string {
targpath = filepath.Clean(targpath)
if fileName, err := filepath.Rel(curDir, targpath); err == nil && len(fileName) <= len(targpath) {
targpath = fileName
}
return targpath
}
// SmarkStack stack information
func SmarkStack(skip int, a ...interface{}) string {
_, fileName, line, ok := runtime.Caller(skip + 1)
if !ok {
return ""
}
fileName = getRelativeDirectory(fileName)
return fmt.Sprintf("%s:%d %s", fileName, line, fmt.Sprint(a...))
}
// SmarkStackFunc stack information
func SmarkStackFunc(skip int, a ...interface{}) string {
pc, fileName, line, ok := runtime.Caller(skip + 1)
if !ok {
return ""
}
funcName := runtime.FuncForPC(pc).Name()
funcName = filepath.Base(funcName)
fileName = getRelativeDirectory(fileName)
return fmt.Sprintf("%s:%d %s %s", fileName, line, funcName, fmt.Sprint(a...))
}
Go
1
https://gitee.com/wzshiming/ffmt.git
git@gitee.com:wzshiming/ffmt.git
wzshiming
ffmt
ffmt
master

搜索帮助