// ----- stdafx.h 헤더파일 ------//
// stdafx.h
#undef TRACE
void TRACE( char *pFormat, ... );
// ----- stdafx.cpp 파일 ------//
// stdafx.cpp : source file that includes just the standard includes
#include "stdafx.h"
#include <afxmt.h>
#include <io.h>
static CCriticalSection g_cs;
#define LOG_PATH "C:\\log.txt"
void TRACE( char *pFormat, ... )
{
char path[] = LOG_PATH;
g_cs.Lock();
CFile f;
f.Open( path, CFile::modeCreate CFile::modeWrite CFile::modeNoTruncate );
f.SeekToEnd();
char buff[1024];
va_list arglist;
va_start( arglist, pFormat );
vsprintf( buff , pFormat, arglist );
va_end( arglist );
OutputDebugString( buff );
CTime t = CTime::GetCurrentTime();
CString strTime;
strTime.Format( "%02d:%02d:%02d ", t.GetHour(), t.GetMinute(), t.GetSecond() );
f.Write( strTime, strTime.GetLength() );
strcat( buff, "\r\n" );
f.Write( buff, strlen(buff) );
f.Close();
g_cs.Unlock();
}
// stdafx.h
#undef TRACE
void TRACE( char *pFormat, ... );
// ----- stdafx.cpp 파일 ------//
// stdafx.cpp : source file that includes just the standard includes
#include "stdafx.h"
#include <afxmt.h>
#include <io.h>
static CCriticalSection g_cs;
#define LOG_PATH "C:\\log.txt"
void TRACE( char *pFormat, ... )
{
char path[] = LOG_PATH;
g_cs.Lock();
CFile f;
f.Open( path, CFile::modeCreate CFile::modeWrite CFile::modeNoTruncate );
f.SeekToEnd();
char buff[1024];
va_list arglist;
va_start( arglist, pFormat );
vsprintf( buff , pFormat, arglist );
va_end( arglist );
OutputDebugString( buff );
CTime t = CTime::GetCurrentTime();
CString strTime;
strTime.Format( "%02d:%02d:%02d ", t.GetHour(), t.GetMinute(), t.GetSecond() );
f.Write( strTime, strTime.GetLength() );
strcat( buff, "\r\n" );
f.Write( buff, strlen(buff) );
f.Close();
g_cs.Unlock();
}
덧글을 달아 주세요