void CLogFile::Close() { #ifdef _MT CPMUTEX amutex(&m_mutex); #endif close(); }
static void add_mutex_set(Action **list, size_t *nb, Action *a) { size_t i; if (a->id < 2) return; if (!opt.sequential) for (i = 0; i < *nb; i++) if (!amutex(a, list[i])) return; list[(*nb)++] = a; }
bool CLogFile::Open(char *szLogPath, int LogFileMode) { #ifdef _MT CPMUTEX amutex(&m_mutex); #endif if (szLogPath!=NULL && szLogPath[0]!='\0') strncpy(logpath,szLogPath,sizeof(logpath)); logpath[sizeof(logpath)-1]='\0'; mode = LogFileMode; return(open()); }
void CLogFile::WriteLogEx(int level, char *pFormat, ...) { va_list pArg; char chMsg[8192]; int i; #ifdef _MT CPMUTEX amutex(&m_mutex); #endif struct tm tmloc; time_t curtime; time(&curtime); memcpy(&tmloc,localtime(&curtime),sizeof(tmloc)); sprintf(chMsg,"%02d/%02d %02d:%02d:%02d ", tmloc.tm_mon+1, tmloc.tm_mday, tmloc.tm_hour, tmloc.tm_min, tmloc.tm_sec ); //getfmttime(0,1,chMsg); //strcat(chMsg," "); i = strlen(chMsg); sprintf(chMsg+i,"%d Level%d -- ",getpid(),level); i = strlen(chMsg); va_start(pArg,pFormat); vsprintf(chMsg+i,pFormat,pArg); va_end(pArg); i = strlen(chMsg); if (chMsg[i-2]!='\n') { strcat(chMsg,"\n"); } if (logdate!=((tmloc.tm_year+1900)*100+tmloc.tm_mon+1)*100+tmloc.tm_mday) open(); #ifdef SYSLOG int slevel; if (level<10000) slevel = LOG_INFO; else slevel = LOG_CRIT; syslog(slevel|LOG_USER,"%s",chMsg); #else if (fp!=NULL) { fprintf(fp,"%s",chMsg); if (curtime-lastftime>flashdelay) { fflush(fp); lastftime = curtime; } } #endif if (level>=g_ShowLogLevel) printf("%s",chMsg); }
void CLogFile::ToFlush() { #ifdef _MT CPMUTEX amutex(&m_mutex); #endif #ifdef SYSLOG #else if (fp!=NULL) { fflush(fp); lastftime = time(NULL); } #endif }