Skip to content

Commit

Permalink
AddSkipPackageFromStackTrace refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstol committed Dec 11, 2019
1 parent 04ae225 commit 1a7ae54
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 0 additions & 8 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var (
bufferPool *sync.Pool

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

// Positions in the call stack when tracing to report the calling method
Expand Down Expand Up @@ -148,12 +147,6 @@ func (entry *Entry) WithTime(t time.Time) *Entry {
return &Entry{Logger: entry.Logger, Data: entry.Data, Time: t, err: entry.err, Context: entry.Context}
}

// AddSkipPackageFromStackTrace
// ex: logrus.AddSkipPackageFromStackTrace("github.com/go-xorm/xorm")
// func AddSkipPackageFromStackTrace(name string) {
// skipPackageNameForCaller[name] = struct{}{}
// }

// 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 {
Expand Down Expand Up @@ -194,7 +187,6 @@ func getCaller() *runtime.Frame {
//pkg := getPackageName(f.Function)

// If the caller isn't part of this package, we're done
//if pkg != logrusPackage {a
if _, has := skipPackageNameForCaller[getPackageName(f.Function)]; !has {
return &f
}
Expand Down
4 changes: 3 additions & 1 deletion exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func SetReportCaller(include bool) {
std.SetReportCaller(include)
}

// AddSkipPackageFromStackTrace ...
// AddSkipPackageFromStackTrace excludes package names from the caller report when
// SetReportCaller set to true. Commonly used to skip a custom logrus wrapper package frames.
// ex. log.AddSkipPackageFromStackTrace("mycoolapp/mylogger") // skip mycoolapp/mylogger wrapper.
func AddSkipPackageFromStackTrace(name string) {
std.AddSkipPackageFromStackTrace(name)
}
Expand Down
4 changes: 2 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ func (logger *Logger) SetOutput(output io.Writer) {
logger.Out = output
}

// SetReportCaller ...
// SetReportCaller logs the caller stack frame.
func (logger *Logger) SetReportCaller(reportCaller bool) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.ReportCaller = reportCaller
}

// AddSkipPackageFromStackTrace ...
// AddSkipPackageFromStackTrace excludes a package from the caller report.
func (logger *Logger) AddSkipPackageFromStackTrace(name string) {
skipPackageNameForCaller[name] = struct{}{}
}
Expand Down

0 comments on commit 1a7ae54

Please sign in to comment.