Skip to content

Commit

Permalink
Fix go1.12 test regression
Browse files Browse the repository at this point in the history
Breakage is due to this change in go 1.12:

Tracebacks, runtime.Caller, and runtime.Callers no longer include compiler-generated initialization functions. Doing a traceback during the initialization of a global variable will now show a function named PKG.init.ializers.

Fix rs#137
  • Loading branch information
rs committed Feb 27, 2019
1 parent 299ff03 commit 6d6350a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go:
- "1.8"
- "1.9"
- "1.10"
- "1.11"
- "1.12"
- "master"
matrix:
allow_failures:
Expand Down
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ func (c Context) Interface(key string, i interface{}) Context {
type callerHook struct{}

func (ch callerHook) Run(e *Event, level Level, msg string) {
// Three extra frames to skip (added by hook infra).
e.caller(CallerSkipFrameCount + 3)
// Extra frames to skip (added by hook infra).
e.caller(CallerSkipFrameCount + contextCallerSkipFrameCount)
}

var ch = callerHook{}
Expand Down
7 changes: 7 additions & 0 deletions go112.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build go1.12

package zerolog

// Since go 1.12, some auto generated init functions are hidden from
// runtime.Caller.
const contextCallerSkipFrameCount = 2
5 changes: 5 additions & 0 deletions not_go112.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build !go1.12

package zerolog

const contextCallerSkipFrameCount = 3

0 comments on commit 6d6350a

Please sign in to comment.