用于调试的printf函数和自定义log函数
来源:互联网 发布:php post 返回json 编辑:程序博客网 时间:2024/05/09 07:46
1. 用宏定义调试用的DPRINT
#define DEBUG_ENABLE#ifdef DEBUG_ENABLE#define DPRINT(fmt, args...) fprintf(stderr, "[DPRINT...][%s %d] "fmt"\n", __FILE__, __LINE__, ##args); #else#define DPRINT(fmt, ...) #endif发布时,将#define DEBUG_ENABLE去掉即可
2. 自定义的log函数模型:
char LogLastMsg[128]; // all info of the last log, all the info to log last timeint Log2Stderr = LOG_ERR; //control Loging to stderr/** * @Synopsis a log func demo * demo for how user defined module log info * * @Param priority: level of log, LOG_ERR, LOG_DEBUG etc. * @Param errno: errno * @Param fmt: format of message to log * @Param ...: args follow by fmt */void mylog(int priority, int errno, char* fmt, ...){ DPRINT("mylog Begin..."); char priVc[][8] = {"Emerg", "Alert", "Crit", "Error", "Warning", "Notice", "Info", "Debug"}; char* priPt = priority < 0 || priority >= sizeof(priVc)/sizeof(priVc[0]) ? "Unknow priority!" : priVc[priority]; char *errMsg = errno <= 0 ? NULL : (const char*)strerror(errno); { va_list argPt; unsigned Ln; va_start(argPt, fmt); //now argPt is point to mylog's param:... Ln = snprintf(LogLastMsg, sizeof(LogLastMsg), "[mylog...][%s]: ", priPt); Ln += vsnprintf(LogLastMsg + Ln, sizeof(LogLastMsg) - Ln, fmt, argPt); if (NULL != errMsg) { Ln += snprintf(LogLastMsg + Ln, sizeof(LogLastMsg) - Ln, "%d:%s", errno, errMsg); } va_end(argPt); } //choose the log which should be show on stderr if (priority < LOG_ERR || priority <= Log2Stderr) { fprintf(stderr, "%s\n", LogLastMsg); } DPRINT("log to stderr"); //always to syslog syslog(priority, "%s", LogLastMsg); if (priority <= LOG_ERR) { exit(-1); } return ;}
1 0
- 用于调试的printf函数和自定义log函数
- 用于调试的printf函数和自定义log函数
- 函数和对象-用于调试,检查点
- log函数封装,让WIN32和android ndk共用相同的log函数,方便调试
- log函数封装,让WIN32和android ndk共用相同的log函数,方便调试
- javascript 和 jq 的调试 用console.log() 函数
- javascript 和 jq 的调试 用console.log() 函数
- 封装printf函数,让log可以打印文件名和行号
- puts()函数和printf函数的区别
- puts()函数和printf函数的区别
- 总结几种log打印printf函数的宏定义
- 总结几种log打印printf函数的宏定义
- 总结几种log打印printf函数的宏定义
- 总结几种log打印printf函数的宏定义
- 总结几种log打印printf函数的宏定义
- 总结几种log打印printf函数的宏定义
- 总结几种log打印printf函数的宏定义
- C 调试LOG函数
- opengl GLSL基本语法 学习 随笔二
- NLP分析技术的三个层面
- U-boot的环境变量值得注意的有两个: bootcmd 和bootargs。
- 黑马程序员-------- java面向对象 封装、构造函数、this static关键字、单例设计
- 工作日志
- 用于调试的printf函数和自定义log函数
- STM32和uc/osii学习笔记之开始规划篇
- Java网络爬虫的实现
- socket 由浅入深系列------socket 阻塞 与 非阻塞(五)
- cocoStudio Animation Editor制作的序列帧动画在cocos2dx 3.0 中使用
- 软件架构————协同构建
- CENTOS 7 安装SAMBA全命令过程
- 关于配置IP地址的、动静态由域策略转换脚本
- 如何把List<T>转成XML操作、增删改查