By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

Debug logs

P: n/a
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.

Jun 13 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 2007-06-13 11:26, Javier wrote:
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.

--
Erik Wikström
Jun 13 '07 #2

P: n/a
Javier wrote:
>

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.

Jun 13 '07 #3

P: n/a
Ok, thanks.

Jun 13 '07 #4

P: n/a

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__'.

--
Bob R
POVrookie
Jun 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.