diff --git a/go.mod b/go.mod index b031982303..402dddfedf 100644 --- a/go.mod +++ b/go.mod @@ -151,8 +151,8 @@ require ( k8s.io/kubernetes v1.12.3 sigs.k8s.io/yaml v1.1.0 // indirect yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051 - yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b - yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf - yunion.io/x/sqlchemy v0.0.0-20190624021043-a2ed237bb1f7 + yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d + yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30 + yunion.io/x/sqlchemy v0.0.0-20190629024351-0b058bbe38b9 yunion.io/x/structarg v0.0.0-20190625074850-3c0636a9fffe ) diff --git a/go.sum b/go.sum index caaa1ca696..7e88bb5640 100644 --- a/go.sum +++ b/go.sum @@ -389,6 +389,7 @@ go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A= golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -475,9 +476,13 @@ yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051 h1:vtZw2iwGrsARNSwRTREG yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634= yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b h1:Z9z+7iegu0HXuL+S8taVWRd1P4b9JJOgPXIeoqYrj7c= yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE= +yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d h1:59zrDL7Ft+hDukguJRmLr/Gdu/9V75x+yX99ovZwfaA= +yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U= yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf h1:OsKC+2ghZHwp+Ztm/MwKlLKKRiE7QcPG8eTp0GmsHbg= yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= -yunion.io/x/sqlchemy v0.0.0-20190624021043-a2ed237bb1f7 h1:mGfap/bAn7ghA6w6cBxzTiTzSF/pR3C2AEXlOCHc12A= -yunion.io/x/sqlchemy v0.0.0-20190624021043-a2ed237bb1f7/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI= +yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30 h1:6CkrwtX4xeYFqqpdWtQPAVqEnD3aEivPLOLzNKNPAB0= +yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= +yunion.io/x/sqlchemy v0.0.0-20190629024351-0b058bbe38b9 h1:fcWkDven+31hhZIihZQ6ITmTmTiSv8xeF0oaQs/3DaI= +yunion.io/x/sqlchemy v0.0.0-20190629024351-0b058bbe38b9/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI= yunion.io/x/structarg v0.0.0-20190625074850-3c0636a9fffe h1:Wr2EXv72ynwtW+x0VCqWwpsfUBWecaZWnLMgaP3UiTo= yunion.io/x/structarg v0.0.0-20190625074850-3c0636a9fffe/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng= diff --git a/vendor/modules.txt b/vendor/modules.txt index 833dc6484c..1ff59876c7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -724,10 +724,10 @@ k8s.io/kubernetes/pkg/scheduler/api sigs.k8s.io/yaml # yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051 yunion.io/x/jsonutils -# yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b +# yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d yunion.io/x/log yunion.io/x/log/hooks -# yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf +# yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30 yunion.io/x/pkg/util/version yunion.io/x/pkg/utils yunion.io/x/pkg/util/regutils @@ -757,7 +757,7 @@ yunion.io/x/pkg/util/prometheus yunion.io/x/pkg/prettytable yunion.io/x/pkg/util/runtime yunion.io/x/pkg/util/clock -# yunion.io/x/sqlchemy v0.0.0-20190624021043-a2ed237bb1f7 +# yunion.io/x/sqlchemy v0.0.0-20190629024351-0b058bbe38b9 yunion.io/x/sqlchemy # yunion.io/x/structarg v0.0.0-20190625074850-3c0636a9fffe yunion.io/x/structarg diff --git a/vendor/yunion.io/x/log/go.mod b/vendor/yunion.io/x/log/go.mod new file mode 100644 index 0000000000..364a34cffb --- /dev/null +++ b/vendor/yunion.io/x/log/go.mod @@ -0,0 +1,10 @@ +module yunion.io/x/log + +go 1.12 + +require ( + github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b + github.com/sirupsen/logrus v1.4.2 + golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 +) diff --git a/vendor/yunion.io/x/log/go.sum b/vendor/yunion.io/x/log/go.sum new file mode 100644 index 0000000000..db88fbe62b --- /dev/null +++ b/vendor/yunion.io/x/log/go.sum @@ -0,0 +1,27 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/vendor/yunion.io/x/log/hooks/caller.go b/vendor/yunion.io/x/log/hooks/caller.go index 8bb8de6a25..5daefae7fc 100644 --- a/vendor/yunion.io/x/log/hooks/caller.go +++ b/vendor/yunion.io/x/log/hooks/caller.go @@ -18,13 +18,16 @@ import ( "fmt" "runtime" "strings" + "sync" "github.com/sirupsen/logrus" ) const callerDelim = "log" -type CallerHook struct{} +type CallerHook struct { + UpHookPakcageName string +} func isInvokeStep(fun, upfun string) bool { if strings.Contains(fun, callerDelim) && !strings.Contains(upfun, callerDelim) { @@ -33,9 +36,9 @@ func isInvokeStep(fun, upfun string) bool { return false } -func GetCallFields() string { +func (hook *CallerHook) GetCallFields() string { var depth int - for i := 3; i <= 9; i++ { + for i := 10; i <= 10; i++ { pc, _, _, ok := runtime.Caller(i) pcUp, _, _, ok := runtime.Caller(i + 1) @@ -45,7 +48,7 @@ func GetCallFields() string { funcName := runtime.FuncForPC(pc).Name() upFuncName := runtime.FuncForPC(pcUp).Name() - //fmt.Printf("===debug: %d->%q: fname: %q, upName: %q\n", i, f1, funcName, upFuncName) + // fmt.Printf("===debug: %d->%q: fname: %q, upName: %q\n", i, i+1, funcName, upFuncName) if isInvokeStep(funcName, upFuncName) { depth = i + 1 break @@ -62,8 +65,55 @@ func GetCallFields() string { return fmt.Sprintf("%v(%v:%v)", funcName, file, line) } +var ( + // Used for caller information initialisation + callerInitOnce sync.Once + // logrusPackage string + + knownLogrusFrames int = 9 + minimumCallerDepth int = knownLogrusFrames + maximumCallerDepth int = 25 +) + +// getPackageName reduces a fully qualified function name to the package name +// There really ought to be to be a better way... +func GetPackageName(f string) string { + for { + lastPeriod := strings.LastIndex(f, ".") + lastSlash := strings.LastIndex(f, "/") + if lastPeriod > lastSlash { + f = f[:lastPeriod] + } else { + break + } + } + + return f +} + +func (hook *CallerHook) getCaller() string { + pcs := make([]uintptr, maximumCallerDepth) + depth := runtime.Callers(minimumCallerDepth, pcs) + frames := runtime.CallersFrames(pcs[:depth]) + + var meetUpLogPacket bool + for f, again := frames.Next(); again; f, again = frames.Next() { + pkg := GetPackageName(f.Function) + if !meetUpLogPacket { + if pkg == hook.UpHookPakcageName { + meetUpLogPacket = true + } + } else { + funcName := f.Function[strings.LastIndex(f.Function, "/")+1:] + file := f.File[strings.LastIndex(f.File, "/")+1:] + return fmt.Sprintf("%v(%v:%v)", funcName, file, f.Line) + } + } + return "???" +} + func (hook *CallerHook) Fire(entry *logrus.Entry) error { - entry.Data["caller"] = GetCallFields() + entry.Data["caller"] = hook.getCaller() return nil } diff --git a/vendor/yunion.io/x/log/log.go b/vendor/yunion.io/x/log/log.go index 0fa33c0661..7e51dabc4c 100644 --- a/vendor/yunion.io/x/log/log.go +++ b/vendor/yunion.io/x/log/log.go @@ -16,10 +16,10 @@ package log import ( + "runtime" "sync" "github.com/sirupsen/logrus" - "yunion.io/x/log/hooks" ) @@ -149,8 +149,10 @@ func DisableColors() { } func AddHookFormatter(logger *logrus.Logger) { - logger.Hooks.Add(new(hooks.CallerHook)) - + pcs := make([]uintptr, 2) + runtime.Callers(0, pcs) + logrusPackage := hooks.GetPackageName(runtime.FuncForPC(pcs[1]).Name()) + logger.Hooks.Add(&hooks.CallerHook{logrusPackage}) logger.Formatter = &TextFormatter{ TimestampFormat: "060102 15:04:05", SpacePadding: 0, diff --git a/vendor/yunion.io/x/pkg/util/regutils/regutils.go b/vendor/yunion.io/x/pkg/util/regutils/regutils.go index 8597a56b5c..0baa6cdad8 100644 --- a/vendor/yunion.io/x/pkg/util/regutils/regutils.go +++ b/vendor/yunion.io/x/pkg/util/regutils/regutils.go @@ -78,8 +78,8 @@ func init() { EMAIL_REG = regexp.MustCompile(`^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$`) CHINA_MOBILE_REG = regexp.MustCompile(`^1[0-9-]{10}$`) FS_FORMAT_REG = regexp.MustCompile(`^(ext|fat|hfs|xfs|swap|ntfs|reiserfs|ufs|btrfs)`) - US_CURRENCY_REG = regexp.MustCompile(`^(\d{0,3}|((\d{1,3},)+\d{3}))(\.\d*)?$`) - EU_CURRENCY_REG = regexp.MustCompile(`^(\d{0,3}|((\d{1,3}\.)+\d{3}))(,\d*)?$`) + US_CURRENCY_REG = regexp.MustCompile(`^[+-]?(\d{0,3}|((\d{1,3},)+\d{3}))(\.\d*)?$`) + EU_CURRENCY_REG = regexp.MustCompile(`^[+-]?(\d{0,3}|((\d{1,3}\.)+\d{3}))(,\d*)?$`) } func MatchFunction(str string) bool { diff --git a/vendor/yunion.io/x/sqlchemy/update.go b/vendor/yunion.io/x/sqlchemy/update.go index d97b64a3bd..a88cd0ee40 100644 --- a/vendor/yunion.io/x/sqlchemy/update.go +++ b/vendor/yunion.io/x/sqlchemy/update.go @@ -179,7 +179,7 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (UpdateDiffs, error) { } if DEBUG_SQLCHEMY { - log.Infof("Update: %s", buf.String()) + log.Infof("Update: %s %s", buf.String(), vars) } results, err := _db.Exec(buf.String(), vars...) if err != nil {