C++临时打日志

来源:互联网 发布:西部数码域名怎么备案 编辑:程序博客网 时间:2024/05/21 10:03
#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);


原创粉丝点击