Jump to content
  • Advertisement
Sign in to follow this  
elekis

a good logging tools tutorial

This topic is 4818 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

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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++

Share this post


Link to post
Share on other sites
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 file
class 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 files
void 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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!