#pragma once
// inspire by MFC TRACE() marco
class CXLog
{
public:
CXLog(const char *pszFileName, int nLineNo, const char *pszFunction)
: m_pszFileName(pszFileName), m_nLineNo(nLineNo), m_pszFunction(pszFunction)
{}
void __cdecl operator()(const char *format, ...) const
{
_snprintf((char*)szBuf, sizeof(szBuf), "[%s(%d):%s],",
m_pszFileName, m_nLineNo, m_pszFunction);
int nLen = (int)strlen(szBuf);
va_list argptr;
va_start(argptr, format);
_vsnprintf((char*)szBuf + nLen, sizeof(szBuf) - nLen, format, argptr);
va_end(argptr);
printf("%s/n", szBuf);
}
private:
/* unimplemented */
CXLog &__cdecl operator=(const CXLog &right);
const char *const m_pszFileName;
const char *const m_pszFunction;
const int m_nLineNo;
char szBuf[1024];
};
#define XLOG CXLog(__FILE__, __LINE__, __FUNCTION__)
// sample
// XLOG("Hello, val = %d/n", 1);