Friday, 15 January 2016

Print error message in Go

Best way to print the error in Go lang.
You need to import runtime and log packages.
if err != nil {
pc, fn, line, _ := runtime.Caller(1)
message := fmt.Sprintf("[error] %s[%s:%d] %s", runtime.FuncForPC(pc).Name(), fn, line, err.Error())
log.Println(message)
}
view raw error.go hosted with ❤ by GitHub

No comments:

Post a Comment