宏打印函数

可带参数的宏打印函数

最简单的红打印函数(显示行列)

1 #define ANITA_PRINTF(fmt, args...)  \
2 {\
3     printf("[%s][%d][anita]", __FUNCTION__,__LINE__);\
4     printf(fmt, ##args);\
5 }

在项目中,常常需要一些定义的宏打印函数,在此分享一个简单的宏打印函数;

 1 enum DEBUG_LEVEL    /*打印等级*/
 2 {
 3     DEBUG_NONE = 0,
 4     DEBUG_INFO,
 5     DEBUG_ERROR,
 6     DEBUG_MAX_LEVEL,
 7 };
 8 static char const *debug_color[] = {
 9     "\033[0m",         /* no color */
10     "\033[0;32m",      /* green */
11     "\033[0;31m",      /* red */
12     "\033[0;33m",      /* yellow */
13 };
14 #define NO_COLOR "\033[0m"
15 
16 #define CGI_DEBUG(debug_level, fmt, args...) \
17     do{\
18         char cgi_debug[16] = {0}; \
19         unsigned char level = (debug_level >= DEBUG_MAX_LEVEL) ? DEBUG_INFO : debug_level;\
20         if (DEBUG_INFO == level || ((0 != GetValue("cgi_debug", cgi_debug)) && (0 == strcmp("on", cgi_debug)))) { \
21             printf("%s[%s:%s:%d] %s" fmt NO_COLOR, debug_color[DEBUG_MAX_LEVEL], "anita", __func__, \
22                     __LINE__, debug_color[level], ##args);}\
23     while(0);

 

posted @ 2020-10-30 14:03  Anita光子  阅读(227)  评论(0编辑  收藏  举报