I'm trying to write a macro to simplify the use of LOG4CPLUS. But I got some trouble when writing the macro.
This is something in my cpp file:
Logger logger = Logger::getInstance("ManagerServer");
After that, I can log one line like this:
LOG4CPLUS_ERROR(logger, logEvent);
I just want to write a macro, than I can change logEvent to some variable argument. And Use like this:
LogErr("failed");
LogErr("failed times %d", iTimes);
So, I write like this:
#define LogErr(fmt, args...)\
do {\
char szBuf[MAX_LOG_BUFFER_SIZE];\
memset(szBuf, 0, MAX_LOG_BUFFER_SIZE); \
vsnprintf(szBuf, MAX_LOG_BUFFER_SIZE, fmt, ##args); \
LOG4CPLUS_ERROR(logger, szBuf);\
} while(0)
But when I compile. g++ give me this message:
error: expected primary-expression before ')' token
Does any one can help me? I really appreciate it.