打印错误信息的宏
2010-12-23 15:26
253 查看
两个版本:普通信息输出和错误信息输出
note:宏中应增加fflush()函数以及时输出信息。
版本一:
版本二:
版本三:
测试代码:
运行结果:
note:宏中应增加fflush()函数以及时输出信息。
版本一:
#define info(format, ...) printf("@@@info:"format"@@@location:Line:%d, Function:%s,File:%s/n", ##__VA_ARGS__, __LINE__ , __FUNCTION__, __FILE__)
版本二:
#define debug_err(format, ...) do { / if(DEBUG) { / printf("@@@error:"format"@@@location:Line:%d, Function:%s,File:%s/n", ##__VA_ARGS__, __LINE__ , __FUNCTION__, __FILE__); / } / } while(0)
版本三:
#define debug(format, ...) do {\ if(strcmp(strerror(errno), "Success")) {\ system("echo -n `date +%Y.%m.%d-%H:%M:%S`");\ fprintf(stdout, "\tERROR: "format"\tLine:%d, File: %s\n\t\t\tReasonNo:%d\tReason:%s\n", ##__VA_ARGS__, __LINE__ ,__FILE__, errno, strerror(errno) );\ }else {\ fprintf(stdout, format"\n", ##__VA_ARGS__);\ }\ fflush(stdout);\ errno = 0;\ }while(0)
测试代码:
#include <iostream>
#include<stdio.h>
#include<stdarg.h>
#define DEBUG 1
#define info(format, ...) printf("@@@info:"format"@@@location:Line:%d, Function:%s,File:%s/n", ##__VA_ARGS__, __LINE__ , __FUNCTION__, __FILE__)
#define debug_err(format, ...) do { / if(DEBUG) { / printf("@@@error:"format"@@@location:Line:%d, Function:%s,File:%s/n", ##__VA_ARGS__, __LINE__ , __FUNCTION__, __FILE__); / } / } while(0)
int main()
{
char* str = "test";
int i = 123456;
printf("printf 版本:/n");
printf("str: %s, i: %02d/n", str, i);
printf("/ndebug 版本:/n");
debug_err("str: %s, i: %02d/n", str, i);
printf("/nrelease 版本:/n");
info("str: %s, i: %02d/n", str, i);
system("pause");
return 0;
}
运行结果:
相关文章推荐
- spring+ibatis 不打印错误信息
- linux C 打印错误信息和标准输入输出
- C语言下调试信息打印与错误位置定位功能的实现
- mybaitis加载异常调试--错误信息打印与映射结果类加载机制
- linux C 打印错误信息和标准输入输出详细介绍
- logger.error完整打印错误堆栈信息
- python try catch 打印错误信息
- Makefile文件调试跟踪打印警告错误信息
- AFNetworking打印输出服务器返回的错误信息
- php 错误信息级别及打印
- 标准库函数perror用法(打印出错误原因信息字符串)
- python try catch 打印错误信息
- 源码:打印错误信息和调试信息
- backtrace&&backtrace_symbols 查找段错误 打印堆栈信息
- 封装错误信息打印的函数
- [VB.NET]Oracle.DataAccess 连Oracle怎么老出错,try catch 打印出来的错误信息是
- 打印js错误信息
- 根据内核打印的段错误信息分析驱动程序——根据出错PC来分析
- 运行一个项目,却在另一个项目中提示错误信息或打印log日志
- [SoapUI] 重载JSONComparator比对JSON Response,忽略小数点后几位,将科学计数法转换为普通数字进行比对,在错误信息中打印当前循环的case number及其他附加信息