forked from FactomProject/FactomCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.go
More file actions
33 lines (25 loc) · 607 Bytes
/
misc.go
File metadata and controls
33 lines (25 loc) · 607 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package util
import (
"fmt"
"runtime"
"time"
)
// a simple file/line trace function, with optional comment(s)
func Trace(params ...string) {
fmt.Printf("##")
if 0 < len(params) {
for i := range params {
fmt.Printf(" %s", params[i])
}
fmt.Printf(" #### ")
} else {
fmt.Printf(" ")
}
pc := make([]uintptr, 10) // at least 1 entry needed
runtime.Callers(2, pc)
f := runtime.FuncForPC(pc[0])
file, line := f.FileLine(pc[0])
tutc := time.Now().UTC()
timestamp := tutc.Format("2006-01-02.15:04:05")
fmt.Printf("TRACE: %s line %d %s file: %s\n", timestamp, line, f.Name(), file)
}