22 lines
479 B
Go
22 lines
479 B
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"runtime"
|
|
)
|
|
|
|
var goSrcRegexp = regexp.MustCompile(`jinzhu/gorm/.*.go`)
|
|
var goTestRegexp = regexp.MustCompile(`jinzhu/gorm/.*test.go`)
|
|
|
|
// FileWithLineNum get filename with line num for logging
|
|
func FileWithLineNum() string {
|
|
for i := 2; i < 15; i++ {
|
|
_, file, line, ok := runtime.Caller(i)
|
|
if ok && (!goSrcRegexp.MatchString(file) || goTestRegexp.MatchString(file)) {
|
|
return fmt.Sprintf("%v:%v", file, line)
|
|
}
|
|
}
|
|
return ""
|
|
}
|