#define TRACE_EXT(xFormat, ...)\
{\
CTime time = CTime::GetCurrentTime();\
FILE *pFile;\
pFile = fopen("C:\\CPGServerLog.txt", "ab");\
static char pszBuf[512];\
sprintf_s(pszBuf, 512, xFormat, __VA_ARGS__);\
std::stringstream ssmsg;\
ssmsg << time.GetYear() << "." << time.GetMonth() << "." << time.GetDay() << " " << time.GetHour() << ":" << time.GetMinute() << ":" << time.GetSecond() << " " << __FILE__ << " [" << __LINE__ << "] " << std::endl << " " << pszBuf << std::endl;\
if (NULL != pFile)\
{\
fprintf(pFile, "%s\n", ssmsg.str().c_str());\
fclose(pFile);\
}\
}
使用示例:
TRACE_EXT("我的字符串:%s\n", szJson);