Logging Mechanism in C++

A

Avinash

Hello
I want to do some debugging stuff for my C++ program.
I want to have some mechanism by which I can pring function names at
runtime.
like
void function ()
{
LogMessage();
}

This LogMessage function should automatically take filename ( which is
possible using __FILE__ and line number using __LINE__ )
but how to get function name at runtime.

Thanks in Advance.
Avinash
 
M

Matthias =?ISO-8859-1?Q?K=E4ppler?=

Avinash said:
Hello
I want to do some debugging stuff for my C++ program.
I want to have some mechanism by which I can pring function names at
runtime.
like
void function ()
{
LogMessage();
}

This LogMessage function should automatically take filename ( which is
possible using __FILE__ and line number using __LINE__ )
but how to get function name at runtime.

Thanks in Advance.
Avinash

I'm not sure whether this is compiler specific, but I have written a
debugging mechanism for VC++ compilers some time ago, and I remember I used
__FUNCTION__ to log which function I'm currently debugging.

Regards,
Matthias
 
J

Johan

have a look at log4cplus

Johan


Matthias Käppler said:
I'm not sure whether this is compiler specific, but I have written a
debugging mechanism for VC++ compilers some time ago, and I remember I
used
__FUNCTION__ to log which function I'm currently debugging.

Regards,
Matthias
 
D

Default User

Matthias said:
Avinash wrote:
I'm not sure whether this is compiler specific, but I have written a
debugging mechanism for VC++ compilers some time ago, and I remember
I used __FUNCTION__ to log which function I'm currently debugging.


That's not a standard preprocessor identifier (it's gcc, I think). As
of the new C standard, the equivalent there is __func__. I don't know
whether C++ is in the process of adopting that or not.




Brian
 
E

Evan Carew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello
I want to do some debugging stuff for my C++ program.
I want to have some mechanism by which I can pring function names at
runtime.
like
void function ()
{
LogMessage();
}

This LogMessage function should automatically take filename ( which is
possible using __FILE__ and line number using __LINE__ )
but how to get function name at runtime.

Have a look at Boost's test facility at
http://www.boost.org/libs/test/doc/index.html
Thanks in Advance.
Avinash

Evan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBwMChpxCQXwV2bJARAkkrAJ9E1Agm0hS+496vCsHfo7XTQuf5RACdFwg2
+wg6xm59Hpu/1Y6/bPcPRXs=
=y/Pz
-----END PGP SIGNATURE-----
 
M

Matthias =?ISO-8859-1?Q?K=E4ppler?=

Default said:
That's not a standard preprocessor identifier (it's gcc, I think). As
of the new C standard, the equivalent there is __func__. I don't know
whether C++ is in the process of adopting that or not.

I used it with Microsoft Visual C++ 7. So it's probably not gcc specific,
but it may not be standard conformous either.
Does the C++ standard define any preprocessor makros at all? I thought that
would be a compiler/implementation thing.
 

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

Forum statistics

Threads
474,186
Messages
2,570,997
Members
47,586
Latest member
Gilda57E93

Latest Threads

Top