From 006f8e15f29ac981d6afc2a198fa789f376667a0 Mon Sep 17 00:00:00 2001 From: Guillaume Merindol Date: Tue, 16 May 2017 15:42:24 +0200 Subject: [PATCH] Debug: first version of errorf --- gdebug/print.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gdebug/print.go b/gdebug/print.go index d85f58e..cae7416 100644 --- a/gdebug/print.go +++ b/gdebug/print.go @@ -16,6 +16,14 @@ func Debugf(f string, vals ...interface{}) { fmt.Printf(fmt.Sprintf("%s: ", line)+f, vals...) } +// Errorf creates the error, but prepends the filename:line_nb of the creation +func Errorf(f string, vals ...interface{}) error { + stack := strings.Split(string(debug.Stack()), "\n") + line := stack[6] + line = line[strings.LastIndex(line, "/")+1:] + return fmt.Errorf(fmt.Sprintf("%s: ", line)+f, vals...) +} + // CountPrintf prints the debug message along with a prefix number to identify it func CountPrintf(f string, vals ...interface{}) { count++