Linux格式化Log宏

来源:互联网 发布:sso算法 编辑:程序博客网 时间:2024/05/20 20:47

#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"); }\


0 0
原创粉丝点击