#include "StdAfx.h"
|
#include "Edge_Log.h"
|
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#undef THIS_FILE
|
static char THIS_FILE[] = __FILE__;
|
#endif
|
|
/////////////////////////////////////////////////////////////////////////////
|
// CEdge_Log
|
|
CEdge_Log::CEdge_Log()
|
{
|
m_pFileLog = NULL;
|
m_strLogPath = _T("");
|
m_strLogFile = _T("");
|
|
InitializeCriticalSection(&m_csLog);
|
}
|
|
CEdge_Log::~CEdge_Log()
|
{
|
if (m_pFileLog)
|
{
|
delete m_pFileLog;
|
m_pFileLog = NULL;
|
}
|
|
DeleteCriticalSection(&m_csLog);
|
}
|
|
void CEdge_Log::SetPath(CString& strPath, CString& strName, BOOL bDelete, int nRemainCount)
|
{
|
strPath.Replace(_T("/"), _T("\\"));
|
CString str = _T("");
|
str = strPath.Right(1);
|
if (str == _T("\\"))
|
m_strLogPath = strPath;
|
else
|
m_strLogPath = strPath + _T("\\");
|
|
m_strLogPath += strName;
|
|
MakeLogFile();
|
}
|
|
BOOL CEdge_Log::MakeLogFile()
|
{
|
// Log ó¸®
|
if (m_strLogPath.IsEmpty())
|
return FALSE;
|
|
m_TimeLogFile = CTime::GetCurrentTime();
|
m_strLogFile.Format(_T("%s_%02d_%02d.log"), m_strLogPath, m_TimeLogFile.GetMonth(), m_TimeLogFile.GetDay());
|
|
if (m_pFileLog)
|
delete m_pFileLog;
|
|
m_pFileLog = new CFile();
|
|
return TRUE;
|
}
|
|
BOOL CEdge_Log::WriteToFile(CTime& time, CString& strContents)
|
{
|
// ³¯Â¥°¡ ¹Ù²î¸é ÆÄÀϸíÀ» °»½ÅÇØ¼ ¾´´Ù.
|
if ((time.GetMonth() != m_TimeLogFile.GetMonth()) || (time.GetDay() != m_TimeLogFile.GetDay()) || !m_pFileLog)
|
MakeLogFile();
|
|
if (!m_pFileLog->Open(m_strLogFile, CFile::modeWrite))
|
{
|
CFileFind filefind;
|
if(filefind.FindFile(m_strLogFile) == FALSE)
|
{
|
if (!m_pFileLog->Open(m_strLogFile, CFile::modeCreate | CFile::modeWrite))
|
{
|
delete m_pFileLog;
|
m_pFileLog = NULL;
|
}
|
}
|
|
filefind.Close();
|
}
|
|
if (m_pFileLog)
|
{
|
m_pFileLog->SeekToEnd();
|
m_pFileLog->Write(strContents, strContents.GetLength());
|
m_pFileLog->Write("\r\n", static_cast<UINT>(strlen("\r\n")));
|
m_pFileLog->Close();
|
}
|
|
return TRUE;
|
}
|
|
BOOL CEdge_Log::WriteToFile(CTime& time, char* strContents)
|
{
|
// ³¯Â¥°¡ ¹Ù²î¸é ÆÄÀϸíÀ» °»½ÅÇØ¼ ¾´´Ù.
|
if ((time.GetMonth() != m_TimeLogFile.GetMonth()) || (time.GetDay() != m_TimeLogFile.GetDay()) || !m_pFileLog)
|
MakeLogFile();
|
|
if (!m_pFileLog->Open(m_strLogFile, CFile::modeWrite))
|
{
|
CFileFind filefind;
|
if(filefind.FindFile(m_strLogFile) == FALSE)
|
{
|
if (!m_pFileLog->Open(m_strLogFile, CFile::modeCreate | CFile::modeWrite))
|
{
|
delete m_pFileLog;
|
m_pFileLog = NULL;
|
}
|
}
|
|
filefind.Close();
|
}
|
|
if (m_pFileLog)
|
{
|
m_pFileLog->SeekToEnd();
|
m_pFileLog->Write(strContents, static_cast<UINT>(strlen(strContents)));
|
m_pFileLog->Write("\r\n", static_cast<UINT>(strlen("\r\n")));
|
m_pFileLog->Close();
|
}
|
|
return TRUE;
|
}
|
|
void CEdge_Log::DisplayEdgeLog(CString str)
|
{
|
try
|
{
|
EnterCriticalSection(&m_csLog);
|
|
// ÀÔ·ÂÇÒ ¹®ÀÚ¿ ¸¸µé±â.
|
CTime time = CTime::GetCurrentTime();
|
char strTemp[512] = {0, };
|
sprintf_s(strTemp, 512, "%02d-%02d-%02d :%s", time.GetHour(), time.GetMinute(), time.GetSecond(), str);
|
|
WriteToFile(time, strTemp);
|
|
LeaveCriticalSection(&m_csLog);
|
}
|
catch (...)
|
{
|
LeaveCriticalSection(&m_csLog);
|
return;
|
}
|
}
|
|
void CEdge_Log::DisplayEdgeLog(char* str, ...)
|
{
|
va_list list;
|
char strText[256] = {0, };
|
|
char strContents[512] = {0,};
|
va_start(list, str);
|
vsprintf_s(strContents, str, list);
|
va_end(list);
|
|
|
try
|
{
|
EnterCriticalSection(&m_csLog);
|
|
// ÀÔ·ÂÇÒ ¹®ÀÚ¿ ¸¸µé±â.
|
CTime time = CTime::GetCurrentTime();
|
char strTemp[512] = {0, };
|
sprintf_s(strTemp, 512, "%02d-%02d-%02d :%s", time.GetHour(), time.GetMinute(), time.GetSecond(), strContents);
|
|
WriteToFile(time, strTemp);
|
|
LeaveCriticalSection(&m_csLog);
|
}
|
catch (...)
|
{
|
LeaveCriticalSection(&m_csLog);
|
return;
|
}
|
}
|