diff --git a/dnsfilter/helpers.go b/dnsfilter/helpers.go index 68d4ba26..8152f402 100644 --- a/dnsfilter/helpers.go +++ b/dnsfilter/helpers.go @@ -1,6 +1,10 @@ package dnsfilter import ( + "fmt" + "os" + "path" + "runtime" "strings" "sync/atomic" ) @@ -58,3 +62,17 @@ func updateMax(valuePtr *int64, maxPtr *int64) { // swapping failed because value has changed after reading, try again } } + +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.Fprint(os.Stderr, buf.String()) +}