?? sgiplog.cpp
字號:
#include "SGIPLog.h"
CMobilLog::CMobilLog()
{
m_nHan = -1;
memset(m_cFile, 0, sizeof(m_cFile));
strcpy(m_cFile, "./gwmsgid.log");
if ((m_nHan = open(m_cFile, O_WRONLY)) == -1)
{
m_nHan = open(m_cFile, O_WRONLY|O_CREAT|O_TRUNC, 00666);
}
pthread_mutex_init(&m_log_mutex , NULL);
}
CMobilLog::~CMobilLog(void)
{
if (m_nHan != -1)
close(m_nHan);
}
void CMobilLog::add(char *pLog)
{
if (m_nHan < 0)
{
if ((m_nHan = open(m_cFile, O_RDWR)) == -1)
{
if ((m_nHan = open(m_cFile, O_WRONLY|O_CREAT|O_TRUNC)) == -1)
return;
}
}
char cBuf[1024] = "";
memset(cBuf, 0, sizeof(cBuf));
time_t tt = time(NULL);
struct tm *pTime = localtime(&tt);
char cTime[20] = "";
memset(cTime, 0, sizeof(cTime));
sprintf(cTime, "[ %d-%d-%d %d:%d:%d ] ", pTime->tm_year+1900,
pTime->tm_mon+1,
pTime->tm_mday,
pTime->tm_hour,
pTime->tm_min,
pTime->tm_sec);
strcat(cBuf, cTime);
strcat(cBuf, pLog);
int nLen = strlen(cBuf);
int nWrLen = 0;
pthread_mutex_lock(&m_log_mutex);
while (nLen > 0)
{
lseek(m_nHan, 0, SEEK_END);
nLen -= nWrLen;
nWrLen = write(m_nHan, cBuf, nLen);
}
pthread_mutex_unlock(&m_log_mutex);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -