mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
update vendor to fix log caller field missing
This commit is contained in:
Vendored
+3
-3
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
)
|
||||
+27
@@ -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=
|
||||
+55
-5
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -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,
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user