I'm used to this:
class Db {
_Commit(char *file, int line) {
Log("Commit called from %s:%d", file, line);
}
};
#define Commit() _Commit(__FILE__, __LINE__)
but the big problem is that I redefine the word Commit globally, and in a 400k lines application framework it's a problem. And I don't want to use a specific word like DbCommit: I dislike redundancies like db->DbCommit(), or to pass the values manually everywhere: db->Commit(__FILE__, __LINE__) is worst.
So, any advice?
_Commit. Beginning with an underscore and having a capital letter as its second character, it is reserved for the implementation, and your using it means your program has undefined behavior._Commit, which would break your code.addr2line? In that case you could use GCC's __builtin_return_address. Logging addresses instead of names isn't pretty, but presumably you only need to know when something went wrong (which means, rarely), so that might do. The nice thing is that it "just works". I'm passing the last up-to-three callers in exceptions, which works fine (apart from being unwieldy to decipher) too.