Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add skipPackageNameForCaller #898

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions entry.go
Expand Up @@ -15,7 +15,7 @@ var (
bufferPool *sync.Pool

// qualified package name, cached at first use
logrusPackage string
skipPackageNameForCaller = make(map[string]bool, 1)

// Positions in the call stack when tracing to report the calling method
minimumCallerDepth int
Expand All @@ -40,6 +40,11 @@ func init() {
minimumCallerDepth = 1
}

// Set the global qualified package name.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the examples here as well.

func SetSkipPackageNameForCaller(name string) {
tossp marked this conversation as resolved.
Show resolved Hide resolved
skipPackageNameForCaller[name] = true
}

// Defines the key when adding errors using WithError.
var ErrorKey = "error"

Expand Down Expand Up @@ -163,18 +168,21 @@ func getCaller() *runtime.Frame {

// cache this package's fully-qualified name
callerInitOnce.Do(func() {
logrusPackage = getPackageName(runtime.FuncForPC(pcs[0]).Name())

// now that we have the cache, we can skip a minimum count of known-logrus functions
// XXX this is dubious, the number of frames may vary store an entry in a logger interface
minimumCallerDepth = knownLogrusFrames
if len(skipPackageNameForCaller) != 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what is going on here?
I have the impression minimumCallerDepth = knownLogrusFrames should remain the same.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lavoiesl @tossp ,
won't this be unused since we are already including the logrus package in the ignore/skip map?

minimumCallerDepth = knownLogrusFrames + 1
} else {
minimumCallerDepth = knownLogrusFrames
}
skipPackageNameForCaller[getPackageName(runtime.FuncForPC(pcs[0]).Name())] = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I鈥檇 prefer having a local logrusPackage variable, this is quite hard to read.

})

for f, again := frames.Next(); again; f, again = frames.Next() {
pkg := getPackageName(f.Function)

// If the caller isn't part of this package, we're done
if pkg != logrusPackage {
if !skipPackageNameForCaller[pkg] {
return &f
}
}
Expand Down