Running the below code, the stack trace is outputted with the line number of fmt.Print(...)
. But I want to output the line of logError(err)
. I think I need to call xerrors.Caller(1)
to do that but I don't know how. Help me.
import (
"fmt"
"io/ioutil"
"golang.org/x/xerrors"
)
func main() {
_, err := ioutil.ReadFile("")
if err != nil {
logError(err)
return
}
}
func logError(err error) {
fmt.Printf("%+v", xerrors.Errorf(": %w", err))
}