Linux格式化Log宏

#include <time.h>
#include <sys/timeb.h>
#include <sys/time.h>


#define PRINTF_DEBUG(format, ...)  {\
    struct tm *__now; \
    struct timeb __tb; \
    char __datestr[16];\
    char __timestr[16];\
    char __mss[4];\
    ftime(&__tb); \
    __now=localtime(&__tb.time); \
    sprintf(__datestr, "%04d-%02d-%02d", __now->tm_year+1900, __now->tm_mon+1, __now->tm_mday);\
    sprintf(__timestr, "%02d:%02d:%02d", __now->tm_hour, __now->tm_min, __now->tm_sec );\
    sprintf(__mss,"%03d",__tb.millitm);\
    fprintf(stdout, "[%s %s.%s] ", __datestr,__timestr,__mss); \
    fprintf(stdout, "%s [%s, %d]:", (const TChar*)gLogLevelTag[level], (const char*)GetLogName(), GetLogIndex()); \
    fprintf(stdout, format,##__VA_ARGS__);  \
    fprintf(stdout,"\n"); }\


发布了60 篇原创文章 · 获赞 44 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/beyond702/article/details/62458540