From 6d6350a51143b5c0d0a6a3b736ee2b41315f7269 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Wed, 27 Feb 2019 12:01:45 -0800 Subject: [PATCH] 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 --- .travis.yml | 2 ++ context.go | 4 ++-- go112.go | 7 +++++++ not_go112.go | 5 +++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 go112.go create mode 100644 not_go112.go diff --git a/.travis.yml b/.travis.yml index 64d202a..70b67c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ go: - "1.8" - "1.9" - "1.10" +- "1.11" +- "1.12" - "master" matrix: allow_failures: diff --git a/context.go b/context.go index f807802..9eff31a 100644 --- a/context.go +++ b/context.go @@ -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{} diff --git a/go112.go b/go112.go new file mode 100644 index 0000000..e7b5a1b --- /dev/null +++ b/go112.go @@ -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 diff --git a/not_go112.go b/not_go112.go new file mode 100644 index 0000000..4c43c9e --- /dev/null +++ b/not_go112.go @@ -0,0 +1,5 @@ +// +build !go1.12 + +package zerolog + +const contextCallerSkipFrameCount = 3