您的位置:首页 > 其它

用宏实现调试信息之分类过滤

2009-05-15 14:09 218 查看
uint debug_mask;

#define XXX_DEB_ERR 0x01

#define XXX_DEB_INFO 0x02

#define XXX_DEB_YYY 0x04

#define XXX_DEB(flag, args...) /

do{ /

if(debug_mask & (flag)) printf(args); /

} while(0)

void main ()

{

debug_mask |= XXX_DEB_INFO;

XXX_DEB(XXX_DEB_ERR, "/n this is error");

XXX_DEB(XXX_DEB_INFO, "/n this is info");

}

-------------

输出:

this is info

-------------

可以用下面函数简化mask的操作

void xxx_set_debug (ulong mask, boolean set) {

if (set) {

debug_mask |= mask;

} else {

debug_mask &= ~mask;

}

}

另外,在linux下编程还可以用上面的方法+结合下面的代码:

#define WDT_DEBUG_ENABLE /* undef it, just in case */

#ifdef WDT_DEBUG_ENABLE

#ifdef __KERNEL__

# define WDT_DEBUG(fmt, args...) printk(KERN_INFO "WATCH: " fmt, ## args)

#else//usr space

# define WDT_DEBUG(fmt, args...) fprintf(stdout, fmt, ## args)

#endif

#else

# define WDT_DEBUG(fmt, args...) /* not debugging: nothing */

#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: