#include "clog.h"
#include "php_mermsemr_log.h"

void logfmt( TLogLevel level, const char * format, ... ) {
  try {
    //FILELog::ReportingLevel() = level;
    va_list args;
    va_start (args, format);
    if (level > FILELOG_MAX_LEVEL) ;
    else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ;
    else {
      FILE *f = Output2FILE::Stream();
      fprintf(f, "- %s %s [%ld]: %c", 
        NowTime().c_str(), 
        FILELog::ToString(level).c_str(),
        getpid(),
        (level > logDEBUG ? level - logDEBUG : 0, '\t'));
      vfprintf(f, format, args);
      fprintf(f, "\n");
    }
    va_end (args);
  } catch(const std::exception& e) {
    FILE_LOG(logERROR) << e.what();
  }
}
/*
void logfmt( TLogLevel level, const char * format, ... ) {
  try {
    //FILELog::ReportingLevel() = level;
    char buffer[2048];
    va_list args;
    va_start (args, format);
    vsprintf (buffer, format, args);
    //perror (buffer);
    va_end (args);
    FILE_LOG(level) << buffer;
  } catch(const std::exception& e) {
    FILE_LOG(logERROR) << e.what();
  }
}
*/

