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.
39 lines
610 B
Go
39 lines
610 B
Go
6 years ago
|
package log
|
||
7 years ago
|
|
||
|
import (
|
||
7 years ago
|
"path"
|
||
7 years ago
|
"runtime"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
7 years ago
|
// 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
|
||
|
}
|
||
|
|
||
7 years ago
|
//fmt.Printf("%s:%d\n", file, line)
|
||
|
if strings.Contains(file, "go-log/") {
|
||
|
continue
|
||
|
}
|
||
7 years ago
|
/*
|
||
|
// 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
|
||
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
7 years ago
|
*/
|
||
|
return path.Base(file), line
|
||
7 years ago
|
}
|
||
|
|
||
|
return "???", 0
|
||
|
}
|