//cb_log(0, "chenbo", "err", 0, 0, "%d %d", 0, 0);
#ifdef WIN32
#define cb_time(timebuf,timebuflen) {SYSTEMTIME t; GetLocalTime(&t); \
cb_sprintf(timebuf, timebuflen, "%04d-%02d-%02d %02d:%02d:%02d,%03d", t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond,t.wMilliseconds);}
#ifdef __MM3D_LOG_MACRO__
#define cb_log(proc, modulename, level, pbuf, nbuflen, pfmt, ...) \
{\
char timebuf[64] = {0}; cb_time(timebuf, 64);\
if(!(pbuf) || (nbuflen) <= 0)\
{\
char buf[4096] = {0};\
cb_sprintf(buf, sizeof(buf), "%s [%s] [%-16.16s:%5.d] [%s]" pfmt, timebuf, (modulename), cb_filename(__FILE__), __LINE__, (level), __VA_ARGS__);\
if(((pvoid_proc_pvoid)(proc)))\
((pvoid_proc_pvoid)(proc))((void*)(buf));\
else\
printf(buf);\
}\
else{\
cb_sprintf((pbuf), (nbuflen), "%s [%s] [%-16.16s:%5.d] [%s]" pfmt, timebuf, (modulename), cb_filename(__FILE__), __LINE__, (level), __VA_ARGS__);\
if(((pvoid_proc_pvoid)(proc)))\
((pvoid_proc_pvoid)(proc))((void*)(pbuf));\
else\
printf(pbuf);\
}\
}
#else
#define cb_log(proc, modulename, level, pbuf, nbuflen, pfmt, ...)
#endif
#else
#define cb_time(timebuf, timebuflen) {char t[64] = {0}; struct timeval tv; gettimeofday(&tv, NULL); \
strftime(t, 64, "%Y-%m-%d %H:%M:%S", localtime(&tv.tv_sec));\
cb_sprintf(timebuf, timebuflen, "%s,%03d",t,(int)(tv.tv_usec / 1000));}
#ifdef __MM3D_LOG_MACRO__
#define cb_log(proc, modulename, level, pbuf, nbuflen, pfmt, ...) \
{\
char timebuf[64] = {0}; cb_time(timebuf, 64);\
if(!(pbuf)|| (nbuflen) <= 0)\
{\
char ptbuf[4096] = {0};\
std::string fmt(std::string("%s [%s] [%-16.16s:%5.d] [%s]") + std::string(pfmt));\
cb_sprintf(ptbuf, 4095, fmt.c_str(), timebuf, (modulename), cb_filename(__FILE__), __LINE__, (level), ##__VA_ARGS__);\
if(((pvoid_proc_pvoid)(proc)))\
((pvoid_proc_pvoid)(proc))((void*)(buf));\
else\
printf(buf);\
}\
else{\
std::string fmt(std::string("%s [%s] [%-16.16s:%5.d] [%s]") + std::string(pfmt));\
cb_sprintf((pbuf), (nbuflen), fmt.c_str(), timebuf, (modulename), cb_filename(__FILE__), __LINE__, (level), ##__VA_ARGS__);\
if(((pvoid_proc_pvoid)(proc)))\
((pvoid_proc_pvoid)(proc))((void*)(pbuf));\
else\
printf(pbuf);\
}\
}
#else
#define cb_log(proc, modulename, level, pbuf, nbuflen, pfmt, ...)
#endif
#endif
c/c++ 跨平台日志格式化简化版
最新推荐文章于 2023-06-20 10:32:38 发布