-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: log: add flag for displaying function name #47230
Comments
Change https://golang.org/cl/335469 mentions this issue: |
Hi, I've add a PoC CL above. |
/cc @robpike |
That's adding an expensive step, an interesting contrast to the other recent logging proposal that tries to make it cheaper. From an API perspective, you'll soon want more than two new flags to control which function is logged: the one that called log.Print, its parent, and so on. The flags will expand if this is adopted. The log package is a fine basic tool, which is what it was meant to do. There are many external logging packages that provide much richer functionality, and that's the right place to look for this feature. Also, note that it's easy to just put the function name in the call itself, either by hand or automation. The log package itself doing would only add ease, not ability. |
This proposal has been added to the active column of the proposals project |
I am not sure this is worthwhile, since the function name can get quite long, methods have awkward names, closures have no real name, and so on. The file:line is far more precise and useful. That said, it's not expensive, nor does it add more API complexity than the extra flag bit. Presumably you'd want file/line/function to always be in sync, so there wouldn't be an extra 'which function' knob beyond the existing one that controls file/line (the depth argument to Output). Today the code does:
It would have to use the ignored result (pc) and call runtime.FuncForPC to get the name. The file/line lookup was much more expensive than resolving the pc to the function name. So it's not expensive. It just may not be terribly useful. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Proposal
When one wants to have more detailed information from the log messages, they can add
Lshortfile
orLlongfile
flags. However, during debugging, having a function name in logs would provide much better context for the developer than a line number. When having only a line number, developer needs to search the file from logs to gain a better understanding of the error.I'd propose to add a flag to the
log
package for displaying function name (Lfuncname
). Or two flags analogical to file flags. One that will strip the packages and one without.Example
The text was updated successfully, but these errors were encountered: