Sign in to follow this  

Error Logging

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
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 )

#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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this