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

6 years ago
package log
7 years ago
import (
"path"
7 years ago
"runtime"
"strings"
)
// FilelineCaller returns file and line for caller
7 years ago
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
7 years ago
}
return "???", 0
}