Debug logs

J

Javier

Hi all,
thanks for the replies to my posts... Here is one more:

I have a debug-log macro in my code like the following:

--- important_things.h

[...]

#ifdef DEBUG
# ifndef _MSGDEBUG
# define _MSGDEBUG(text); std::cout << std::string(text) <<
std::endl;
# endif
#else
# ifndef _MSGDEBUG
# define _MSGDEBUG(text); /* Nothing */
# endif
#endif


#ifndef _MSGERROR
# define _MSGERROR(text); std::cerr << std::string(text) <<
std::endl;
#endif

[...]

--- myclass.cpp

#include "important_things.h"

[...]

void myclass::myfunc()
{
_MSGDEBUG("myclass::myfunc:: Doing anything important...");

[...]

_MSGERROR("myclass::myfunc:: Ohh no, error I want always to be
printed");

[...]

_MSJDEBUG("myclass::myfunc:: Done.");
}


Now my question is if there is a way of doing the output of
"myclass::myfunc" in an automated way, like if I used the __FILE__ and
__LINE__ (but I prefer the information about function and class to
file and line number).

Of course, if I have more nested ownership (sorry about my english),
it would be perfect that can automatically output
"myclass::mysubclass::myfunc" to avoid writting lot of text in the
calls to _MSGDEBUG() and MSGERROR().

I need it only for debug, but if there is a way of doing this, it
would be perfect to keep it in released bins without so much overload,
and do it with variables so I could activate/deactivate it at runtime
and not at compile time with preprocessor macros.

Thanks.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi all,
thanks for the replies to my posts... Here is one more:

I have a debug-log macro in my code like the following:

--- important_things.h

[...]

#ifdef DEBUG
# ifndef _MSGDEBUG
# define _MSGDEBUG(text); std::cout << std::string(text) <<
std::endl;
# endif
#else
# ifndef _MSGDEBUG
# define _MSGDEBUG(text); /* Nothing */
# endif
#endif


#ifndef _MSGERROR
# define _MSGERROR(text); std::cerr << std::string(text) <<
std::endl;
#endif

[...]

--- myclass.cpp

#include "important_things.h"

[...]

void myclass::myfunc()
{
_MSGDEBUG("myclass::myfunc:: Doing anything important...");

[...]

_MSGERROR("myclass::myfunc:: Ohh no, error I want always to be
printed");

[...]

_MSJDEBUG("myclass::myfunc:: Done.");
}


Now my question is if there is a way of doing the output of
"myclass::myfunc" in an automated way, like if I used the __FILE__ and
__LINE__ (but I prefer the information about function and class to
file and line number).

Of course, if I have more nested ownership (sorry about my english),
it would be perfect that can automatically output
"myclass::mysubclass::myfunc" to avoid writting lot of text in the
calls to _MSGDEBUG() and MSGERROR().

I need it only for debug, but if there is a way of doing this, it
would be perfect to keep it in released bins without so much overload,
and do it with variables so I could activate/deactivate it at runtime
and not at compile time with preprocessor macros.

There's no simple solution that will work on all platforms, but look
into your compiler documentation, on gcc I think it's called __func__,
on VC++ there's at least three different versions, search for predefined
macros in the documentation/on msdn.
 
D

Davlet Panech

Javier said:
Now my question is if there is a way of doing the output of
"myclass::myfunc" in an automated way, like if I used the __FILE__ and
__LINE__ (but I prefer the information about function and class to
file and line number).

There's no standard macro for this, but:
* if you are using GCC you can use __PRETTY_FUNCTION__ which expands to
full function signature.
* C'99 supports __func__ which expands to just the function name, some
C++ compilers may support that as well
* Your compiler may have similar features, check the manuals

D.
 
B

BobR

Erik Wikström wrote in message...
[...]
There's no simple solution that will work on all platforms, but look
into your compiler documentation, on gcc I think it's called __func__,

FYI:
In C99 it's '__func__'.
GNU GCC also has '__FUNCTION__' and '__PRETTY_FUNCTION__'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top