tags:

views:

57

answers:

2

Hi,

I need to automatically prepend method name to some logging messages. I've been using __FUNCTION__ to do it but it generates the fully qualified name of the method ( namespace::class:method ). So it's wasting a lot of space and makes logs less readable. Is there any way to append only the method name in a MACRO, without any unnecessary qualifiers?

+1  A: 

If your logging code looks like this:

#define LOGCALL \
    clog << "Called " << __FUNCTION__ << endl;

then you can simply write a global function to trim the function name as required and say:

#define LOGCALL \
    clog << "Called " << MyTrim( __FUNCTION__ ) << endl;
anon
+1  A: 

Write a function that takes a char* argument and returns a pointer to the function name in it. Then write

MyFunction(FUNCTION)

Instead of

FUNCTION

This has also the advantage that you can dynamically switch between short and long names.

Patrick