3 ms·
If you're logging errors, you can use the runtime package to find out where a logging statement was called. So you can log on error and record the line, functio
by grey-area 13y ago
If you're logging errors, you can use the runtime package to find out
where a logging statement was called. So you can log on error and record the line, function name etc:
pc, _, line, _ := runtime.Caller(1)
name := runtime.FuncForPC(pc).Name()
Not that you need this much, but it is there if you need to return information on exactly where an error came from when logged, just put that in your logging function and whenever you log it'll trace where the log was called from, or you could store the info in your error object if you wish. log4go has some examples of this sort of thing I think. Typically I've only used that when there was an intractable bug though, normally you're not going to need it if your error objects are specific enough, it's easy to find where they came from and store whatever info you want in them, which I assume is what they're doing here.