You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
527 B
Go

package log
import (
"path"
"runtime"
"strings"
)
// FilelineCaller returns file and line for caller
func FilelineCaller(skip int) (file string, line int) {
for i := 0; i < 10; i++ {
_, file, line, ok := runtime.Caller(skip + i)
if !ok {
return "???", 0
}
// in go module mode, the import path like this
// github.com/fangdingjun/go-log@v4.0.1-incomple/
if strings.Contains(file, "go-log/") || strings.Contains(file, "go-log@v") {
continue
}
return path.Base(file), line
}
return "???", 0
}