mirror of https://github.com/go-gorm/gorm.git
Fix logger panic on windows
This commit is contained in:
parent
b32658358c
commit
9934207c42
|
@ -5,25 +5,24 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
var goSrcRegexp, goTestRegexp *regexp.Regexp
|
var gormSourceDir string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_, file, _, _ := runtime.Caller(0)
|
_, file, _, _ := runtime.Caller(0)
|
||||||
goSrcRegexp = regexp.MustCompile(filepath.Join(filepath.Dir(filepath.Dir(file)), ".*.go"))
|
gormSourceDir = filepath.Dir(filepath.Dir(file))
|
||||||
goTestRegexp = regexp.MustCompile(filepath.Join(filepath.Dir(filepath.Dir(file)), ".*test.go"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileWithLineNum() string {
|
func FileWithLineNum() string {
|
||||||
for i := 2; i < 15; i++ {
|
for i := 2; i < 15; i++ {
|
||||||
_, file, line, ok := runtime.Caller(i)
|
_, file, line, ok := runtime.Caller(i)
|
||||||
if ok && (!goSrcRegexp.MatchString(file) || goTestRegexp.MatchString(file)) {
|
|
||||||
|
if ok && (!strings.HasPrefix(file, gormSourceDir) || strings.HasSuffix(file, "_test.go")) {
|
||||||
return fmt.Sprintf("%v:%v", file, line)
|
return fmt.Sprintf("%v:%v", file, line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue