fast/CCEXPipe/stdafx.cpp

67 lines
1.5 KiB
C++
Raw Normal View History

2025-01-20 10:30:01 +08:00
// stdafx.cpp : ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Դ<EFBFBD>ļ<EFBFBD>
// CCEXPipe.pch <20><><EFBFBD><EFBFBD>ΪԤ<CEAA><D4A4><EFBFBD><EFBFBD>ͷ
// stdafx.obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
#include "stdafx.h"
#include <stdio.h>
// TODO: <20><> STDAFX.H <20><>
// <20><><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void LogOutToFile(const char* fmt, ...)
{
static CRITICAL_SECTION stCritical;
static BOOL bInit = FALSE;
static char acLogPath[2148] = {0};
if (FALSE == bInit)
{
bInit = TRUE;
GetModuleFileName(NULL, acLogPath, 2047);
for (int i = strlen(acLogPath)-1; i > 0; i--)
{
if (acLogPath[i] == '\\')
{
acLogPath[i] = '\0';
break;
}
}
strcat(acLogPath, "\\CCEXPipe.log");
InitializeCriticalSection(&stCritical);
}
EnterCriticalSection(&stCritical);
va_list ap;
va_start(ap, fmt);
char pBuffer[800] = "";
if (vsnprintf_s(pBuffer, 796,_TRUNCATE, fmt, ap) > 0)
{
if (strlen(pBuffer) == 0 || pBuffer[strlen(pBuffer)-1] != '\n')
{
pBuffer[strlen(pBuffer)+1] = '\0';
pBuffer[strlen(pBuffer)] = '\n';
}
}
va_end(ap);
FILE* pFile = NULL;
fopen_s(&pFile, acLogPath, "ab+");
if (NULL != pFile)
{
char acTime[32] = {0};
SYSTEMTIME stTime;
GetLocalTime(&stTime);
sprintf_s(acTime, "[%02d-%02d %02d:%02d:%02d.%03d] ", stTime.wMonth, stTime.wDay, stTime.wHour, stTime.wMinute, stTime.wSecond, stTime.wMilliseconds);
fwrite(acTime, 1, strlen(acTime), pFile);
fwrite(pBuffer, 1, strlen(pBuffer), pFile);
fwrite("\r\n", 1, strlen("\r\n"), pFile);
fclose(pFile);
}
LeaveCriticalSection(&stCritical);
}