mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-21 18:36:25 +00:00
logger.WithReportCaller: fix enabled by default
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
724d6103c6
commit
b52ae2c670
@ -105,7 +105,7 @@ type Logger interface {
|
||||
|
||||
type logger struct {
|
||||
fl logrus.Ext1FieldLogger
|
||||
reportCaller int
|
||||
reportCaller *int
|
||||
}
|
||||
|
||||
func (l *logger) Tracef(format string, args ...interface{}) {
|
||||
@ -252,17 +252,16 @@ func (l *logger) WithError(err error) Logger {
|
||||
}
|
||||
|
||||
func (l *logger) WithReportCaller(b bool, depth ...uint) Logger {
|
||||
if !b {
|
||||
return &logger{fl: l.fl}
|
||||
}
|
||||
var d int
|
||||
if b {
|
||||
if len(depth) > 0 {
|
||||
d = int(depth[0])
|
||||
} else {
|
||||
d = 0
|
||||
}
|
||||
} else {
|
||||
d = -1
|
||||
}
|
||||
return &logger{fl: l.fl, reportCaller: d}
|
||||
return &logger{fl: l.fl, reportCaller: &d}
|
||||
}
|
||||
|
||||
func (l *logger) Logr() logr.Logger {
|
||||
@ -310,11 +309,11 @@ func (l *logger) Clone() Logger {
|
||||
}
|
||||
|
||||
func (l *logger) withCaller() logrus.Ext1FieldLogger {
|
||||
if l.reportCaller == -1 {
|
||||
if l.reportCaller == nil {
|
||||
return l.fl
|
||||
}
|
||||
pcs := make([]uintptr, 1)
|
||||
runtime.Callers(3+l.reportCaller, pcs)
|
||||
runtime.Callers(3+*l.reportCaller, pcs)
|
||||
f, _ := runtime.CallersFrames(pcs).Next()
|
||||
pkg := getPackageName(f.Function)
|
||||
return l.fl.WithField("caller", fmt.Sprintf("%s/%s:%d", pkg, filepath.Base(f.File), f.Line)).WithField("func", f.Func.Name())
|
||||
|
Loading…
Reference in New Issue
Block a user