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