编码: UTF-8
缩进: 4
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include <stdio.h>
/** Export define ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#define NONE "\e[0m" //清除颜色,即之后的打印为正常输出,之前的不受影响
#define BLACK "\e[0;30m" //深黑
#define L_BLACK "\e[1;30m" //亮黑,偏灰褐
#define RED "\e[0;31m" //深红,暗红
#define L_RED "\e[1;31m" //鲜红
#define GREEN "\e[0;32m" //深绿,暗绿
#define L_GREEN "\e[1;32m" //鲜绿
#define BROWN "\e[0;33m" //深黄,暗黄
#define YELLOW "\e[1;33m" //鲜黄
#define BLUE "\e[0;34m" //深蓝,暗蓝
#define L_BLUE "\e[1;34m" //亮蓝,偏白灰
#define PURPLE "\e[0;35m" //深粉,暗粉,偏暗紫
#define L_PURPLE "\e[1;35m" //亮粉,偏白灰
#define CYAN "\e[0;36m" //暗青色
#define L_CYAN "\e[1;36m" //鲜亮青色
#define GRAY "\e[0;37m" //灰色
#define WHITE "\e[1;37m" //白色,字体粗一点,比正常大,比bold小
#define BOLD "\e[1m" //白色,粗体
#define UNDERLINE "\e[4m" //下划线,白色,正常大小
#define BLINK "\e[5m" //闪烁,白色,正常大小
#define REVERSE "\e[7m" //反转,即字体背景为白色,字体为黑色
#define HIDE "\e[8m" //隐藏
#define CLEAR "\e[2J" //清除
#define CLRLINE "\r\e[K" //清除行
/** **********************************************
* */
#define DebugNone 0 /* 0 > 关闭 */
#define DebugError 1 /* 1 > 错误信息 */
#define DebugWarning 2 /* 2 > 警告信息和1,发行版置为该选项 */
#define DebugLog 3 /* 3 > 运行日志信息,1,2 */
#define DebugTmp 4 /* 4 > 临时调试信息,和1,2,3 */
/** **********************************************
* @note:该宏并不控制整个程序的打印等级,使用
* #undef DebugLevel
* #define DebugLevel DebugLog_XX
* 调整某个文件的打印等级
* */
#define DebugLevel DebugTmp
/** **********************************************
* @usage: 使用以下定义在特定文件中增加调试日志前缀
* #undef PREFIX
* #define PREFIX "MainThread: "
* */
#define PREFIX ""
#define DEBUG_OUT stdout
/** **********************************************
* */
#define DebugP(lv,clr,fmt,...) \
if (DebugLevel >= lv) \
fprintf(DEBUG_OUT, clr PREFIX fmt NONE, ##__VA_ARGS__)
/* 错误信息 */
#define DebugE(fmt,...) \
({\
DebugP(DebugError, L_RED, fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 警告信息 */
#define DebugW(fmt,...) \
({\
DebugP(DebugWarning, YELLOW, fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 日志信息 */
#define DebugL(fmt,...) \
({\
DebugP(DebugLog, BOLD, fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 日志信息,蓝色 */
#define DebugLB(fmt,...) \
({\
DebugP(DebugLog, L_BLUE, fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 临时调试信息,灰色 */
#define DebugT(fmt,...) \
({\
DebugP(DebugTmp, GRAY,fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 临时调试信息,蓝色 */
#define DebugB(fmt,...) \
({\
DebugP(DebugTmp, L_BLUE,fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 临时调试信息,蓝色 */
#define DebugTL_CYAN(fmt,...) \
({\
DebugP(DebugTmp, L_CYAN,fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/* 临时调试信息,自选颜色 */
#define DebugTC(color,fmt,...) \
({\
DebugP(DebugTmp, color, fmt, ##__VA_ARGS__);\
fflush(DEBUG_OUT);\
})
/** ***************************************************
* @note: 可用来辅助定位程序崩溃位置,
* 打印当前执行的文件,行数,函数名,调试用
* */
#define __HELP__ \
({\
DebugTC(L_PURPLE,"%s %d %s\n",__FILE__,__LINE__,__func__);\
fflush(DEBUG_OUT);\
})
/** Export typedef +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/** Export functions +++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/** Export variables +++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#endif /* __DEBUG_H__ */