-
Notifications
You must be signed in to change notification settings - Fork 64
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
Added SOURCE_LOC macro #388
Conversation
|
||
#define STRINGIFY(x) #x | ||
#define TOSTRING(x) STRINGIFY(x) | ||
#define SOURCE_LOC " (" __FILE__ ":" TOSTRING(__LINE__) ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs to me that this solution is also useful with build/verbosity macros. Should use those here to conditionally define SOURCE_LOC
only for debug builds. In production, this will produce paths that probably aren't meaningful, or at least would only be useful in a bug report with a version we could check out and find the right relative file from the absolute paths this reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. We can turn these off in non-debug builds, sure, but actually I think they could still provide meaningful paths in the case of catching exceptions in production (which shouldn't happen, right?). The build path might be throwaway, but the trailing path and filename are still useful for the same reasons they are useful in dev. Since this is compile-time evaluated I don't think there's much cost, other than maybe infinitesimally larger binaries. I'd tend to vote to leave it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, just thought it might be odd if you have a build system creating binaries that then report paths that don't even exist when an error is logged. I'm good with it as is for the time being.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's not uncommon in my experience--potentially a little confusing but you quickly figure out what's going on. Something that just occurs to me... should we try embedding the Git commit ID into the file and hence the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh...that's messier than it at first looks. Maybe not, or maybe later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe later...
After merging this I decided to do a little digging on #ifndef _NGEN_ALL
#define _NGEN_ALL
#endif //_NGEN_ALL Just to ensure consistence with the rest of the code and not rely on a "non-standard" feature. |
Adds an easy way to improve exception messages (or other logging output)
Additions
Added a
SOURCE_LOC
macro inall.h
that can be used to easily (and sustainably) report the location in code from which an exception was thrown or a log message was written.Also adds some examples of use
Removals
Changes
Testing
cerr
write is present that can be used to check the result.Screenshots
Notes
Todos
Checklist
Testing checklist (automated report can be put here)
Target Environment support