📄 cmtracer.cpp
字号:
#include <MatrixCore/System/CMTracer.h>
#include <TChar.h>
#include <direct.h>
#include <Mmsystem.h>
using namespace MatrixCore::System;
CMTracerConsole::CMTracerConsole()
: handleConsole( INVALID_HANDLE_VALUE )
{
}
CMTracerConsole::~CMTracerConsole()
{
}
bool CMTracerConsole::open( LPCTSTR out )
{
handleConsole = ::GetStdHandle( STD_OUTPUT_HANDLE );
if( handleConsole == INVALID_HANDLE_VALUE )
{
if( ::AllocConsole() == FALSE )
{
::FreeConsole();
return false;
}
handleConsole = ::GetStdHandle( STD_OUTPUT_HANDLE );
if( handleConsole == INVALID_HANDLE_VALUE )
return false;
}
return true;
}
void CMTracerConsole::output( LPCTSTR str ) throw (CMConsoleAbortException)
{
DWORD size;
//捞何盒 何磐 遏捞 吧赴促
#ifdef THREADSAFE
CMSynchronized( this );
#endif
::WriteFile( handleConsole, str, strlen( str ), &size, 0 );
}
void CMTracerConsole::close()
{
if( handleConsole != INVALID_HANDLE_VALUE )
{
::CloseHandle( handleConsole );
handleConsole = INVALID_HANDLE_VALUE;
}
}
//-----------------------------
// Tracer File
CMTracerFile::CMTracerFile()
{
//糕滚 函荐 檬扁拳
ZeroMemory(m_cLogBuffer, sizeof(m_cLogBuffer));
ZeroMemory(m_cLogFilePathName, sizeof(m_cLogFilePathName));
ZeroMemory(m_cLogFileName, sizeof(m_cLogFileName));
}
CMTracerFile::~CMTracerFile()
{
}
bool CMTracerFile::open( LPCTSTR out )
{
char cTmpStr[MAX_PATH];
char *pToken;
char *pOldToken;
strcpy(m_cLogFileName,out);
strcpy(cTmpStr,out);
pToken = strtok(cTmpStr,"\\/");
while(pToken != NULL)
{
pOldToken = pToken;
pToken = strtok(NULL,"\\/");
if(pToken == NULL)
break;
strcat(m_cLogFilePathName,pOldToken);
strcat(m_cLogFilePathName,"\\");
_tmkdir(m_cLogFilePathName);
}
return true;
}
void CMTracerFile::output( LPCTSTR str) throw( CMFileAbortException )
{
char cTempBuffer[512];
SYSTEMTIME SysTime;
DWORD dwTime;
FILE * pLogFile = NULL;
int iStrSize;
//捞何盒 何磐 遏捞 吧赴促
#ifdef THREADSAFE
CMSynchronized( this );
#endif
dwTime = timeGetTime();
GetLocalTime(&SysTime);
ZeroMemory(cTempBuffer, sizeof(cTempBuffer)) ;
wsprintf(cTempBuffer, "%04d:%02d:%02d:%02d:%02d:%02d\t",SysTime.wYear,SysTime.wMonth,SysTime.wDay,SysTime.wHour,SysTime.wMinute, SysTime.wSecond);
strcat(cTempBuffer, str);
strcat(cTempBuffer, "\n");
strcat(m_cLogBuffer, cTempBuffer) ;
iStrSize = (int) strlen(m_cLogBuffer);
// 肺弊 滚欺俊 滚欺啊 芭狼 菜蛮版快 FILELOGSIZEBUFFER - 816
// 趣篮 肺弊甫 敬瘤 5檬啊 瘤抄版快
if ( iStrSize >= FILELOGSIZEBUFFER - 816 || (dwTime - m_dwLogTime > 5*1000) ) {
ZeroMemory(cTempBuffer, sizeof(cTempBuffer)) ;
wsprintf(cTempBuffer,"%s%04d%02d%02d.log",m_cLogFileName,SysTime.wYear,SysTime.wMonth,SysTime.wDay) ;
pLogFile = fopen(cTempBuffer, "at");
if (pLogFile == NULL) return;
fwrite(m_cLogBuffer, 1, iStrSize, pLogFile);
if (pLogFile != NULL) fclose(pLogFile);
m_dwLogTime = dwTime ;
ZeroMemory(m_cLogBuffer, sizeof(m_cLogBuffer));
}
}
void CMTracerFile::close()
{
//弊府绊 付瘤阜 妓促款矫绰 公炼扒 历厘茄促.
char cTempBuffer[512];
SYSTEMTIME SysTime;
FILE * pLogFile = NULL;
if(strlen(m_cLogBuffer) <= 0)
{
return ;
}
ZeroMemory(cTempBuffer, sizeof(cTempBuffer)) ;
GetLocalTime(&SysTime);
wsprintf(cTempBuffer,"%s%04d%02d%02d.log",m_cLogFileName,SysTime.wYear,SysTime.wMonth,SysTime.wDay) ;
pLogFile = fopen(cTempBuffer, "at");
int err = ::GetLastError();
if (pLogFile == NULL) return;
fwrite(m_cLogBuffer, 1, strlen(m_cLogBuffer), pLogFile);
if (pLogFile != NULL) fclose(pLogFile);
}
//-----------------------------
// Tracer Debug trace window
CMTracerTrace::CMTracerTrace()
{
}
CMTracerTrace::~CMTracerTrace()
{
}
bool CMTracerTrace::open( LPCTSTR out )
{
return true;
}
void CMTracerTrace::output( LPCTSTR str )
{
char cTempBuffer[512];
strcpy(cTempBuffer,str);
strcat(cTempBuffer, "\n");
#ifdef THREADSAFE
CMSynchronized( this );
#endif
OutputDebugString( cTempBuffer );
}
void CMTracerTrace::close()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -