Fix go1.12 test regression

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 #137
This commit is contained in:
Olivier Poitrey 2019-02-27 12:01:45 -08:00
parent 299ff038c1
commit 6d6350a511
4 changed files with 16 additions and 2 deletions

View File

@ -4,6 +4,8 @@ go:
- "1.8"
- "1.9"
- "1.10"
- "1.11"
- "1.12"
- "master"
matrix:
allow_failures:

View File

@ -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{}

7
go112.go Normal file
View File

@ -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
not_go112.go Normal file
View File

@ -0,0 +1,5 @@
// +build !go1.12
package zerolog
const contextCallerSkipFrameCount = 3