1. Log.h ( 로그파일, 출력을 도와주는 클래스 )
/** \file Log.h
** \date 2007/12/10
** \author kimjunju@hotmail.com
**/
#pragma once
/** \class CLog
\brief 시간을 기준으로 로그를 남긴다.
\remark static 멤버함수로 선언하여 객체없이 함수를 이용가능하다.
*/
/** \ingroup UTIL */
class CLog
{
public:
static BOOL WriteLog(LPTSTR data, ...)
{
_wsetlocale(LC_ALL, _T("korean")); // 한글을 출력하기 위한 설정.
SYSTEMTIME SystemTime;
TCHAR CurrentDate[32] = {0,};
TCHAR CurrentFileName[MAX_PATH] = {0,};
FILE* FilePtr = NULL;
TCHAR DebugLog[MAX_BUFFER_LENGTH] = {0,};
va_list ap;
TCHAR Log[MAX_BUFFER_LENGTH] = {0,};
va_start(ap, data);
_vstprintf(Log, data, ap);
va_end(ap);
GetLocalTime(&SystemTime);
_sntprintf(CurrentDate, 32, _T("%d-%d-%d %d:%d:%d"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour,
SystemTime.wMinute,
SystemTime.wSecond);
_sntprintf(CurrentFileName, MAX_PATH, _T("LOG_%d-%d-%d %d.log"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour);
FilePtr = _tfopen(CurrentFileName, _T("a"));
if (!FilePtr)
return FALSE;
_ftprintf(FilePtr, _T("[%s] %s\n"), CurrentDate, Log);
_sntprintf(DebugLog, MAX_BUFFER_LENGTH, _T("[%s] %s\n"), CurrentDate, Log);
fflush(FilePtr);
fclose(FilePtr);
OutputDebugString(DebugLog);
_tprintf(_T("%s"), DebugLog);
return TRUE;
}
static BOOL WriteLogNoDate(LPTSTR data, ...)
{
_wsetlocale(LC_ALL, _T("korean"));
SYSTEMTIME SystemTime;
TCHAR CurrentDate[32] = {0,};
TCHAR CurrentFileName[MAX_PATH] = {0,};
FILE* FilePtr = NULL;
TCHAR DebugLog[MAX_BUFFER_LENGTH] = {0,};
va_list ap;
TCHAR Log[MAX_BUFFER_LENGTH] = {0,};
va_start(ap, data);
_vstprintf(Log, data, ap);
va_end(ap);
GetLocalTime(&SystemTime);
_sntprintf(CurrentDate, 32, _T("%d-%d-%d %d:%d:%d"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour,
SystemTime.wMinute,
SystemTime.wSecond);
_sntprintf(CurrentFileName, MAX_PATH, _T("LOG_%d-%d-%d %d.log"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour);
FilePtr = _tfopen(CurrentFileName, _T("a"));
if (!FilePtr)
return FALSE;
_ftprintf(FilePtr, _T("%s"), Log);
_sntprintf(DebugLog, MAX_BUFFER_LENGTH, _T("%s"), Log);
fflush(FilePtr);
fclose(FilePtr);
OutputDebugString(DebugLog);
_tprintf(_T("%s"), DebugLog);
return TRUE;
}
};
** \date 2007/12/10
** \author kimjunju@hotmail.com
**/
#pragma once
/** \class CLog
\brief 시간을 기준으로 로그를 남긴다.
\remark static 멤버함수로 선언하여 객체없이 함수를 이용가능하다.
*/
/** \ingroup UTIL */
class CLog
{
public:
static BOOL WriteLog(LPTSTR data, ...)
{
_wsetlocale(LC_ALL, _T("korean")); // 한글을 출력하기 위한 설정.
SYSTEMTIME SystemTime;
TCHAR CurrentDate[32] = {0,};
TCHAR CurrentFileName[MAX_PATH] = {0,};
FILE* FilePtr = NULL;
TCHAR DebugLog[MAX_BUFFER_LENGTH] = {0,};
va_list ap;
TCHAR Log[MAX_BUFFER_LENGTH] = {0,};
va_start(ap, data);
_vstprintf(Log, data, ap);
va_end(ap);
GetLocalTime(&SystemTime);
_sntprintf(CurrentDate, 32, _T("%d-%d-%d %d:%d:%d"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour,
SystemTime.wMinute,
SystemTime.wSecond);
_sntprintf(CurrentFileName, MAX_PATH, _T("LOG_%d-%d-%d %d.log"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour);
FilePtr = _tfopen(CurrentFileName, _T("a"));
if (!FilePtr)
return FALSE;
_ftprintf(FilePtr, _T("[%s] %s\n"), CurrentDate, Log);
_sntprintf(DebugLog, MAX_BUFFER_LENGTH, _T("[%s] %s\n"), CurrentDate, Log);
fflush(FilePtr);
fclose(FilePtr);
OutputDebugString(DebugLog);
_tprintf(_T("%s"), DebugLog);
return TRUE;
}
static BOOL WriteLogNoDate(LPTSTR data, ...)
{
_wsetlocale(LC_ALL, _T("korean"));
SYSTEMTIME SystemTime;
TCHAR CurrentDate[32] = {0,};
TCHAR CurrentFileName[MAX_PATH] = {0,};
FILE* FilePtr = NULL;
TCHAR DebugLog[MAX_BUFFER_LENGTH] = {0,};
va_list ap;
TCHAR Log[MAX_BUFFER_LENGTH] = {0,};
va_start(ap, data);
_vstprintf(Log, data, ap);
va_end(ap);
GetLocalTime(&SystemTime);
_sntprintf(CurrentDate, 32, _T("%d-%d-%d %d:%d:%d"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour,
SystemTime.wMinute,
SystemTime.wSecond);
_sntprintf(CurrentFileName, MAX_PATH, _T("LOG_%d-%d-%d %d.log"),
SystemTime.wYear,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wHour);
FilePtr = _tfopen(CurrentFileName, _T("a"));
if (!FilePtr)
return FALSE;
_ftprintf(FilePtr, _T("%s"), Log);
_sntprintf(DebugLog, MAX_BUFFER_LENGTH, _T("%s"), Log);
fflush(FilePtr);
fclose(FilePtr);
OutputDebugString(DebugLog);
_tprintf(_T("%s"), DebugLog);
return TRUE;
}
};
Tag | 유니코드