Exemplo n.º 1
0
Arquivo: Log.cpp Projeto: imane-jym/gp
void Log::LogFileChange()
{
	ChangeLogFile("LogFile");
	ChangeLogFile("CharLogFile");
	ChangeLogFile("ChatLogFile");

    logfile = openLogFile("LogFile", NULL, "a");
    charLogfile = openLogFile("CharLogFile", NULL, "a");
    chatLogfile = openLogFile("ChatLogFile", NULL, "a");
}
Exemplo n.º 2
0
void CMyLog::Log(unsigned char level, const wchar_t* str)
{	
	static wchar_t LogLevelString[][10] = { L"ERROR", L"INFO ", L"DEBUG" };
	if (level > m_ucLevel)
	{
		return;
	}

	WaitForSingleObject(m_hMutex, INFINITE);
	time_t timer = time(NULL);
	struct tm *tmt = localtime(&timer);
	/* to log file */
	if (m_fp)
	{
		fwprintf(m_fp, L"%04d-%02d-%02d %02d:%02d:%02d %s %s\n",
			tmt->tm_year + 1900,
			tmt->tm_mon + 1,
			tmt->tm_mday,
			tmt->tm_hour,
			tmt->tm_min,
			tmt->tm_sec,
			LogLevelString[level],
			str);

		fflush(m_fp);
		ChangeLogFile();
	}

	ReleaseMutex(m_hMutex);
}
Exemplo n.º 3
0
//------------------------------------------------------------------------
bool	CLogFile::Init(const TCHAR * pszPath)
{
	if (!PathIsFolder(pszPath))
	{
		if (!CreateDirectory(pszPath, NULL))
			return false;
	}
	o_strncpy(m_szFile, pszPath, 1023);
	ChangeLogFile();
	m_bIsInit = true;
	return true;
}
Exemplo n.º 4
0
void CMyLog::Log(unsigned char level, const wchar_t* file, int line, const wchar_t* fmt, ...)
{	
	static wchar_t LogLevelString[][10] = {L"ERROR", L"INFO ", L"DEBUG"};

	if (level > m_ucLevel)
	{
		return;
	}

	WaitForSingleObject(m_hMutex, INFINITE);
	time_t timer = time(NULL);
	struct tm *tmt = localtime(&timer);
	va_list arg;

	/* to log file */
	if (m_fp)
	{
		fwprintf(m_fp, L"%04d-%02d-%02d %02d:%02d:%02d %s ",
			tmt->tm_year + 1900,
			tmt->tm_mon + 1,
			tmt->tm_mday,
			tmt->tm_hour,
			tmt->tm_min,
			tmt->tm_sec,
			LogLevelString[level]);

		/* log content */
		va_start(arg, fmt);
		vfwprintf(m_fp, fmt, arg);
		va_end(arg);

		/* log file */
		fwprintf(m_fp, L" %s:%d\n", file, line);
		fflush(m_fp);
		ChangeLogFile();
	}

	ReleaseMutex(m_hMutex);
}