Created
April 10, 2019 03:05
-
-
Save peacefixation/fc40b028476fac2aa1e396443688fd1d to your computer and use it in GitHub Desktop.
Trace function name, line number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func trace() string { | |
pc := make([]uintptr, 15) | |
n := runtime.Callers(2, pc) // 2 -> the calling function's frame details | |
frames := runtime.CallersFrames(pc[:n]) | |
if frame, ok := frames.Next(); ok { | |
// frame.File is the full file path | |
return fmt.Sprintf("%s:%d", frame.Function, frame.Line) | |
} | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment