a good logging tools tutorial

Started by
5 comments, last by elekis 18 years, 7 months ago
hi boys, I looking for a good tutorial about log class. I know there are lots of library about that, but I would like learn how to make that, and most of all how to use, etc...etc... I googelised with "log class tutorial" but nothing. any idea. thanks a++
Advertisement
Here's a great tutorial on using XML to make a better log class if you are interested. Other than that, there's not much to making a log class. You just start with something simple and slowly expand based on how you desire for things to work. Most of the time though, people will use existing libraries and modify them to their needs. One that is used a lot is the Logger Class from Fluid Studios. Good luck!
in fact, my question is, how to use, what the main goal about a log file. (if I wanna make my own class)

what the ultimate goal, push in all function
Log::GetInstnce() << "I m in this function" << endl;

or or only on a constructor object??

how to use that???

but thanks for the links, I ve just became (is it english ??) to read.

a++
Yes, the overall goal is to be able to simply log whatever you need to do. I mean your logging class can be something like this:
// .H fileclass CLog{private:   ofstream outFile;public:   CLog( string fileName )   {      outFile.open( fileName.c_str() );   }   void Log( string data )   {      outFile << data;   }   ~CLog()   {      outFile.close();   }};extern CLog Logger;// In your .CPP filesvoid Function1(){   if( x < 100 )   {      Logger.Log("x is less than 100");   }}


You of course could use the singleton approach with the Log::GetInstnce() as you have said as well. It's your call [wink].

As for why you want to use Logs, simply because you can easily send information there and check it rather than have to find it out in a debugger.

For example, if you have a OpenGL program, if you want to see the values of a variable at some location, you can either add in a font class and output it to the window, or you can easily just send it to a log file and check it there. It's to make your life easier when it comes to tracing bugs and fixing problems.

That's about it really, do you have a better idea of logging now, or do you need more explanations?
If you want to have a syntax like Log::GetInstnce() << "I m in this function" << endl; you can use std::ostream.
Log inherits from std::ostream and you use an attribute Logbuf which inherits from std::basic_stream_buf<char>. In this last class you override member function overflow.
After that you add a GetInstance member function to Log which return a reference on the Log's unique instance.
thanks a lot, its better clear now

a++
in fact, I have may be a other question,

is a log must write on differents out in the sames times???
I take a exemples, counter-strikes
there was a log in the consoles and a log in a file (fo exemple log.out)


was it the same log or or two different log?? and was is the same written function who do that???

exemple log::Write(string msg){
file << msg;
cout << msg;
}

or it's two different log???

in fact it's because, n the first time I tried to make one class Clog with a flag system , you know,
CLog MyLog(COUT_FLAG,FILE_FLAG) by exemple but is it the best goal??

thanks

a++

This topic is closed to new replies.

Advertisement