用宏实现调试信息之分类过滤
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
#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
相关文章推荐
- 根据仿人人客户端教程,编程实现Demo(三)---根据新鲜事过滤列表,分类显示新鲜事信息
- 【Python 编程】实现文本分类中的信息增益算法
- 朴素贝叶斯实现垃圾信息分类
- 微信jsSDK本地调试流程攻略(nodeJs实现获取access_token等信息)
- Android程序调试–LogCat按照日志信息级别进行输出和过滤
- ztree实现ajax调用商品分类信息树状显示
- android学习之android logat 调试及信息过滤
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- 商城项目-使用json模板实现带分类的产品规格信息存储及展示
- 51单片机单串口同时实现AT指令和调试信息输出
- (二十五)后台开发-分类信息的curd -展示所有实现
- Function实现ALV Table七:汇总,分类汇总,排序,过滤
- 用signal实现调试信息的动态控制——syslog和signal
- Log4j 如何实现 根据不同的类 或者不同的包 输出的调试信息到不同的文件夹中
- 基于热点短信息分类的研究与实现-2008年硕士论文答辩PPT
- Android Studio IDE的 LogCat如何过滤指定应用的调试信息
- CSS3实战开发: 纯CSS实现图片过滤分类显示特效
- C语言下调试信息打印与错误位置定位功能的实现
- Android程序调试–LogCat按照日志信息级别进行输出和过滤
- Qt调试信息分类和qDebug()导出到文…