Own means of c ++ do not allow to know anything about the context of a function call.
The call stack can be analyzed using some external operating system libraries / APIs. For example: http://man7.org/linux/man-pages/man3/backtrace.3.html https://msdn.microsoft.com/en-us/library/ms680650%28VS.85%29.aspx . But for the use of these tools may impose additional restrictions on the collected code (assembly with debug information, etc.).
It is more reasonable, IMHO, to transfer the context of the call explicitly: this will allow you to use the "regular" means of c ++: __FILE__ , __LINE__ , __func__ , .... You can disguise the context extraction with the macro:
struct Context{ const char* file; unsigned line; const char* function; }; // Work around MSVS #ifndef __func__ #define __func__ __FUNCTION__ #endif #define CONTEXT() Context({ __FILE__, __LINE__, __func__}) void foo( int a, int b, Context c ); #define FOO(a, b) foo( a, b, CONTEXT() )
The class name can be extracted either by __FUNCTION__ name __FUNCTION__ , or from the this pointer:
typeid(this).name()
But I don’t want to include this call to this in a macro, since functions can be called from a context, a static function.
On the other hand, for the purposes of log separation, __FILE__ may be enough.