Boring But Important: logfiles
Posted: Sun Jan 15, 2006 1:24 am
It looks like I'm going for the award for the Most Unexciting Irrlicht Related Tutorial Ever award here. If you're not using a logfile for your debugging output, then I'd really recommend you start. If nothing else, the massive advantage they have over simple printf() calls is that you can output as much as you like without it getting lost up the top of the output window.
I've written a very simple error log system, simply a class that writes things to a file for you. As you can see in the header, the class is already declared when the file is included, so you don't need to initialise it or anything. To use it, do this:
Download here
And yes, it does the cool formatted text thing like printf(). Go Me.
Only one thing, in order to get at it every source file needs to #include "CErrorLog.h" - I use a "Global.h" which has Irrlicht includes and everything, but if you don't then make sure you include this everywhere.
Here's the header, just so you can see what's going on:
I've written a very simple error log system, simply a class that writes things to a file for you. As you can see in the header, the class is already declared when the file is included, so you don't need to initialise it or anything. To use it, do this:
Code: Select all
// in your code somewhere
if(somethingGoesWrong == true)
{
logfile.writeEntry("something went wrong - my ostrich is %d metres tall", ostrich.getLength());
}
And yes, it does the cool formatted text thing like printf(). Go Me.
Only one thing, in order to get at it every source file needs to #include "CErrorLog.h" - I use a "Global.h" which has Irrlicht includes and everything, but if you don't then make sure you include this everywhere.
Here's the header, just so you can see what's going on:
Code: Select all
#ifndef __CERRORLOG_H
#define __CERRORLOG_H
#include <stdarg.h>
class CErrorLog
{
public:
CErrorLog();
CErrorLog(char *logfilename);
~CErrorLog();
void writeEntry(char *entry, ...);
void close();
private:
FILE *logfile;
};
//static CErrorLog *logfile;
static CErrorLog logfile;
#endif