0

Hi
friends can you send me links OR tell me how to write log files in C++ using events i have got some link from Google but it is not helpful

can anyone please help me with some example code

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

Maybe you could be a little more specific?

For example, what sort of log file are you looking to create?
What events?

0

If you want to write error logs, you can redirect the streambuf of the std::err to
the local file.Then you just write to the std::err with << operators.

actually same as you write to a file.

Are you asking about the exceptions? Then you can set up your SEH routine and
inside that routine you can open the file and just write to it.There is no
magical way.

0

Well Friends i have to do the testing part so i have to write the log files weather to check there is error or not i hope i am clear

1

I suppose ther are as many ways to write a logger as there are progammers. The way I did it was to write a funtion that took a const char* as parameter (the message to be logged), open the log file, write out the message, then close the file. Its a very simple function. Then you can call that function as many times in your program as you want to.

If you only want to do the logging when the program is compiled for degging then you might do something like this:

void log(const char* message)
{
#ifdef _DEBUG
   // code to log messages go here
#endif
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.