• Advertisement
Sign in to follow this  

Error Logging

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've seen it where an error log contains the source file name, line number, etc where the error took place. I have been able to figure that part of the error simply includes what file it is in, but since line numbers change constantly, how is that found and output?

Share this post


Link to post
Share on other sites
Advertisement
Assuming c/c++.


The preprocessor will change __LINE__ and __FILE__ to values which show up the actual file and line numbers.

So your log could be like this:


void log( const std::string &file, int line, const std::string &message )
{
//output;
}

#define log(M) log(__FILE__,__LINE__,(M) )




Now we can use log("Hello World"); and let the compiler do the hard work for us.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement