#ifndef _DEBUG_H__
#define _DEBUG_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <errno.h>
#include <string.h>
#include <sys/timeb.h>
#include <time.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1):__FILE__)
#define Error(...) \
do{ \
struct tm *ptm;\
struct timeb stTimeb;\
static char szTime[32] = {0};\
ftime(&stTimeb);\
ptm = localtime(&stTimeb.time);\
sprintf(szTime, "%02d:%02d:%02d.%03d",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, stTimeb.millitm);\
fprintf(stderr, "%s[ERROR ]%s:%d:%s()",szTime,__FILENAME__,__LINE__,__FUNCTION__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
}while(0)
#define Warning(...) \
do{ \
struct tm *ptm;\
struct timeb stTimeb;\
static char szTime[32] = {0};\
ftime(&stTimeb);\
ptm = localtime(&stTimeb.time);\
sprintf(szTime, "%02d:%02d:%02d.%03d",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, stTimeb.millitm);\
fprintf(stdout, "%s[WARNING]%s:%d:%s()",szTime,__FILENAME__,__LINE__,__FUNCTION__); \
fprintf(stdout, __VA_ARGS__); \
fprintf(stdout, "\n"); \
}while(0)
#define Info(...) \
do{ \
struct tm *ptm;\
struct timeb stTimeb;\
static char szTime[32] = {0};\
ftime(&stTimeb);\
ptm = localtime(&stTimeb.time);\
sprintf(szTime, "%02d:%02d:%02d.%03d",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, stTimeb.millitm);\
fprintf(stdout, "%s[INFO ]%s:%d:%s()",szTime,__FILENAME__,__LINE__,__FUNCTION__); \
fprintf(stdout, __VA_ARGS__); \
fprintf(stdout, "\n"); \
}while(0)
#define Debug(...) \
do{ \
struct tm *ptm;\
struct timeb stTimeb;\
static char szTime[32] = {0};\
ftime(&stTimeb);\
ptm = localtime(&stTimeb.time);\
sprintf(szTime, "%02d:%02d:%02d.%03d",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, stTimeb.millitm);\
fprintf(stdout, "%s[DEBUG ]%s:%d:%s()",szTime,__FILENAME__,__LINE__,__FUNCTION__); \
fprintf(stdout, __VA_ARGS__); \
fprintf(stdout, "\n"); \
}while(0)
#ifdef __cplusplus
}
#endif
#endif
10:59:17.105[DEBUG ]main.cpp:111:main()debug
10:59:17.105[INFO ]main.cpp:112:main()info
10:59:17.105[WARNING]main.cpp:113:main()warning
10:59:17.105[ERROR ]main.cpp:114:main()error
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)