Add trace() for debugging
This commit is contained in:
parent
620212ad37
commit
119d38fa8e
15
helpers.go
15
helpers.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
@ -246,3 +247,17 @@ func _Func() string {
|
||||||
f := runtime.FuncForPC(pc[0])
|
f := runtime.FuncForPC(pc[0])
|
||||||
return path.Base(f.Name())
|
return path.Base(f.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func trace(format string, args ...interface{}) {
|
||||||
|
pc := make([]uintptr, 10) // at least 1 entry needed
|
||||||
|
runtime.Callers(2, pc)
|
||||||
|
f := runtime.FuncForPC(pc[0])
|
||||||
|
var buf strings.Builder
|
||||||
|
buf.WriteString(fmt.Sprintf("%s(): ", path.Base(f.Name())))
|
||||||
|
text := fmt.Sprintf(format, args...)
|
||||||
|
buf.WriteString(text)
|
||||||
|
if len(text) == 0 || text[len(text)-1] != '\n' {
|
||||||
|
buf.WriteRune('\n')
|
||||||
|
}
|
||||||
|
fmt.Print(buf.String())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue