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.
35 lines
531 B
Go
35 lines
531 B
Go
package formatters
|
|
|
|
import (
|
|
"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
|
|
}
|
|
|
|
// file = pkg/file.go
|
|
n := 0
|
|
for i := len(file) - 1; i > 0; i-- {
|
|
if file[i] == '/' {
|
|
n++
|
|
if n >= 2 {
|
|
file = file[i+1:]
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if !strings.HasPrefix(file, "go-log/") {
|
|
return file, line
|
|
}
|
|
}
|
|
|
|
return "???", 0
|
|
}
|