Skip to content

Instantly share code, notes, and snippets.

@YanhaoYang
Created February 15, 2017 06:37
Show Gist options
  • Save YanhaoYang/5889af8df093663063b5a4ad7b0b4feb to your computer and use it in GitHub Desktop.
Save YanhaoYang/5889af8df093663063b5a4ad7b0b4feb to your computer and use it in GitHub Desktop.
Print caller info
package main
import (
"fmt"
"path"
"runtime"
)
func callerInfo() string {
function, file, line, _ := runtime.Caller(0)
return fmt.Sprintf("%s@%s:%d", runtime.FuncForPC(function).Name(), path.Base(file), line)
}
func main() {
fmt.Println(callerInfo())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment