Skip to content

Commit

Permalink
Debug: first version of errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
gee-m committed May 16, 2017
1 parent 0a6d4f7 commit 006f8e1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gdebug/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down

0 comments on commit 006f8e1

Please sign in to comment.