import ( "fmt" "log" "runtime" ) // Debug prints a debug information to the log with file and line. func DebugFunInfo(format string, a ...interface{}) { funName := "" pc, file, line, ok := runtime.Caller(1) info := fmt.Sprintf(format, a...) // https://stackoverflow.com/questions/35212985/is-it-possible-get-information-about-caller-function-in-golang details := runtime.FuncForPC(pc) if ok && details != nil { funName = details.Name() //fmt.Printf("called from %s\n", details.Name()) } log.Println("debug", funName, "file:", file, "(", line, ") ", info) } func main() { DebugFunInfo ("start") }
alexnetster@gmail.com/ 나중에 재사용시 흔적을 남겨 찾기 쉽게 하는 것이 목적/ 최대한 간단하게.