#include <string>
#include <stdio.h>
#include <stdarg.h>
namespace OFX {
static FILE *gLogFP = 0;
static std::string gLogFileName("ofxTestLog.txt");
void
logSetFileName(const std::string &value)
{
gLogFileName = value;
}
const std::string &
logGetFileName()
{
return gLogFileName;
}
bool
logOpenFile(void)
{
if(!gLogFP) {
gLogFP = fopen(gLogFileName.c_str(), "w");
}
return gLogFP != 0;
}
void
logCloseFile(void)
{
if(gLogFP) {
fclose(gLogFP);
}
gLogFP = 0;
}
void
logPrint(const char *format, ...)
{
if(logOpenFile()) {
va_list args;
va_start(args, format);
vfprintf(gLogFP, format, args);
fputc('\n', gLogFP);
fflush(gLogFP);
va_end(args);
}
}
void
logWarning(bool condition, const char *format, ...)
{
if(condition && logOpenFile()) {
fputs("WARNING : ", gLogFP);
va_list args;
va_start(args, format);
vfprintf(gLogFP, format, args);
fputc('\n', gLogFP);
va_end(args);
fflush(gLogFP);
}
}
void
logError(bool condition, const char *format, ...)
{
if(condition && logOpenFile()) {
fputs("ERROR : ", gLogFP);
va_list args;
va_start(args, format);
vfprintf(gLogFP, format, args);
fputc('\n', gLogFP);
va_end(args);
fflush(gLogFP);
}
}
};