#include <cassert>
#include <iostream>
#include <syslog.h>
#include <sys/time.h>
#include <unistd.h>
#include "mindlog.h"
#include "wwwi/mutexholder.h"
using WWWI::MutexHolder;
MINDLog::MINDLog() {
m_lya = new LogPriority[(unsigned)LF_MAX];
m_smp = &std::cerr;
this->SetPriority(LY_DEBUG);
this->SetMethod(LM_TERMINAL);
}
void MINDLog::Log(LogFacility i_lf, LogPriority i_ly, const char *i_strMessage) {
MutexHolder mh(&m_mx);
char strTime[128];
time_t tm;
assert(i_strMessage!=NULL);
if (this->WouldLog(i_lf,i_ly)==false) return;
if (*i_strMessage==0) return;
switch(m_lm) {
case LM_TERMINAL:
time(&tm);
strftime(strTime,128,"%b %d %H:%M:%S",localtime(&tm));
assert(m_smp!=NULL);
(*m_smp) << strTime << " mnamed[" << getpid() << "]: " << i_strMessage << endl;
break;
case LM_SYSLOG:
syslog(SyslogPri(i_ly),i_strMessage);
break;
default:
assert("Unknown log method!"==0);
}
}
MINDLog::~MINDLog() {
FastLog(LF_OBJNEWDEL,LY_DEBUG,"MINDLog::~MINDLog()");
m_smp = NULL;
delete[] m_lya;
}