[Solved] Logging with compiler generated constants

This topic is 3905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I've got a logging system where every time I log a message I want to say where in the code that message came from. Currently I have:
Log("gfxengine.c","Initalise","Failed to set screen resolution");


Which logs... "12/10/2007 10:33:12 - gfxengine.c(Initalise) - Failed to set screen resolution" It's quite tedious having to the tell the Log routine something which the compiler should already know, where in the code we currently are. Ideally I could just use something along the lines of:
Log(__File,__Procedure,"Failed to set screen resolution");


Where the compiler fills in the details automatically. Unfortunately I can't see anything in the VS Cpp Express 2005 documentation to suggest that this feature might exist. Anyone know??? [Edited by - Racky1275 on October 12, 2007 7:31:03 AM]

Share on other sites
There's always the __FILE__ and __LINE__ preprocessor macros (as well as __TIME__ and __DATE__). Some compilers have extensions for getting the function name as well.

Share on other sites
Wow fast response! Thanks, I'll have a look at those.

Share on other sites
Yep! __FILE__ / __FUNCTION__ / __LINE__ should do the trick nicely.

• 16
• 11
• 11
• 9
• 49
• Forum Statistics

• Total Topics
631394
• Total Posts
2999749
×