好用的C C++ 日志宏 OutputDebugStringA 写到文件或界面
日志宏
#include <cstdio>
#define OUTPUT_DEBUG_STRING(fmt, ...) do { \char szOutMsgFinal[10240] = {0}; \std::snprintf(szOutMsgFinal, sizeof(szOutMsgFinal), "[%s|%d] " fmt "\n", __func__, __LINE__, ##__VA_ARGS__); \OutputDebugStringA(szOutMsgFinal); \printf(szOutMsgFinal); \
} while(0)
或者 日志函数 到界面
void DbgPrintf(LPCSTR pszFormat, ...)
{char szOutMsg[1024];char szOutMsgFinal[1024+16];va_list argList;va_start(argList, pszFormat);vsprintf(szOutMsg, pszFormat, argList);va_end(argList);sprintf(szOutMsgFinal, "#DBG::%s\n", szOutMsg);OutputDebugStringA(szOutMsgFinal);
}
# 写到文件或界面
# 分级的写到文件
# C#写日志