📄 mmdebug.cpp
字号:
#include "pch.h"
#include "mmdebug.h"
FILE* g_pLogfile = NULL;
BOOL g_bFirstTime = TRUE;
CRITICAL_SECTION crFile;
BOOL g_bInitCS = FALSE;
void Mmdprintf(int MmDebugLevel, char* szFormat, ...)
{
#ifdef _DEBUG
char buf[256];
char tmpbuf[128];
time_t ltime;
struct tm now;
long fileSize = 0;
va_list argptr; // Used by va_start
va_start(argptr, szFormat); // Multiple parameter start
vsprintf(tmpbuf, szFormat, argptr);
va_end(argptr);
time(<ime);
now = *localtime(<ime);
sprintf(buf, "%d/%d %d:%d:%d\t%s\n", now.tm_mon+1, now.tm_mday,
now.tm_hour, now.tm_min, now.tm_sec, tmpbuf);
if (MmDebugLevel & MmDebugLevelLog)
{
MmOpenDebugLogfile();
if (g_pLogfile)
{
fileSize = ftell(g_pLogfile);
if ((fileSize / 1024) / 1024 >= 10) // max is 10MB
rewind(g_pLogfile);
fwrite (buf, sizeof(char), strlen(buf), g_pLogfile);
}
MmCloseDebugLogfile();
}
if (MmDebugLevel & MmDebugLevelTrace)
#ifdef _WINDOWS
OutputDebugString (buf);
#else
printf("%s", buf);
#endif // _WINDOWS
#endif
}
void MmCloseDebugLogfile()
{
if (g_pLogfile != NULL)
fclose (g_pLogfile);
g_pLogfile = NULL;
OSLeaveCriticalSection(&crFile);
}
void MmOpenDebugLogfile()
{
if (!g_bInitCS)
{
g_bInitCS = TRUE;
OSInitializeCriticalSection(&crFile);
}
OSEnterCriticalSection(&crFile);
if (g_pLogfile == NULL)
{
if (g_bFirstTime)
{
g_bFirstTime = FALSE;
g_pLogfile = fopen("mmlog.txt", "w+");
}
else
g_pLogfile = fopen("mmlog.txt", "a+");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -