-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: runtime: CallerString #71519
Comments
Related Documentation (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
What would the string be? I'm not sure what you mean when you suggest replacing it at compile time. It seems to me that is only possible when the caller is known. And that can only happen if the function that calls |
I doesn't matter precisely what the string is as long as it
It could just be "path/file:lineNumber". I'm not concerned about the particulars as long as it is meets the listed criteria. Say you had a function using it like func F() T {
return G(runtime.CallerString(1))
} I'm imagining some hypothetical set of optimizations where |
It would serve a similar purpose. This is about providing a nicer interface. The last place I used something like this was a parser for strings that would be provided in source (like how |
#52751 sounds related, though that's more specialized to tests |
The runtime package provides all the necessary primitives, and it's not obvious to me from its name what kind of string CallerString would actually return; and I can easily imagine wanting to tweak it a little. This merely convenient feature might be better provided by the internal library within your project, tailored to your specific needs. |
The necessary primitives are not especially friendly and their generality makes the simple case overly complicated. Getting basic info about a single frame is the common case by volume and it would be nice to have a clear, simple, robust way to get that. |
@jimmyfrasche You say above that the string has to be machine readable, which means that it must be precisely defined. This proposal isn't going to go anywhere unless you provide a precise definition. Thanks. |
Proposal Details
This proposal is for a function with a signature like
func CallerString(skip int) string
.It returns basic info about the caller in some fixed format.
Since it only returns info about a single frame and only reports it as simple data, when
skip
is a reasonable constant, it could be replaced at compile time as an optimization. Otherwise, it can be implemented in terms ofCallers
.Either way, it would simplify common logging/monitoring/error annotating uses that just need a tiny bit of context about a single caller for reporting to a developer.
The text was updated successfully, but these errors were encountered: