Best way to print the error in Go lang.
You need to import runtime and log packages.
You need to import runtime and log packages.
This file contains 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
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) | |
} |
No comments:
Post a Comment