1.printf()自定义函数
#define DEBUG
#define LOG_TAG "MIC_DEBUG"
#ifdef DEBUG
#include <stdio.h>
#define debug(fmt, x...) printf("%s: %s() line: %d "fmt, LOG_TAG, __FUNCTION__, __LINE__, ##x);
#else
#define debug(fmt, x...)
#endif
int main()
{
int num = 4567;
debug("num = %d\n", num);
}
2.printk()自定义函数
1、定义
#define LOG_TAG "[Camera]: %s() line: %d "
#define Camera_ERR(fmt, args...) printk(KERN_ERR LOG_TAG fmt, __FUNCTION__, __LINE__, ##args)
2、打印函数
void test(){
Camera_ERR("%s\n", __func__);
}
3、输出log为:
[Camera] test
printf/printk 增加tag
最新推荐文章于 2022-06-26 15:08:30 发布
本文深入探讨了在C语言中如何自定义打印函数,包括使用printf()和printk()函数进行日志记录的方法。通过具体示例展示了如何在代码中实现自定义的日志输出格式,这对于理解和调试程序运行过程中的状态具有重要作用。
665

被折叠的 条评论
为什么被折叠?



