📄 debug.h
字号:
/************************************************************************ Copyright (C), 2005, islab@ZJUFileName: debug.cAuthor: htgo Date: 2005-07-23Description:定义了如下调试方法1. 标准输入输出,方便重定向2. 断言3. 调试信息,分类型输出:Waring, Alerting, Debug,Log4. 调试信息分级输出5. 调试信息输出开关History:1.Date: 2005-07-28Author: htgoModify: 1. 增加了Log信息输出的时间信息2. 增加了调试开关 *************************************************************************/#ifndef DEBUG_H#define DEBUG_H#include <stdio.h>#include <time.h>/*给Log信息加一个时间信息*/time_t timep;struct tm *pLocalTime;/*调试开关*/#define DVS_INFO_ON 1#define DVS_ERROR_FLAG DVS_INFO_ON#define DVS_WARING_FLAG DVS_INFO_ON#define DVS_ALERT_FLAG DVS_INFO_ON#define DVS_DEBUG_FLAG DVS_INFO_ON#define DVS_LOG_FLAG DVS_INFO_ON/*标准输入输出,方便重定向*/#define DVS_STDIN stdin#define DVS_STDOUT stdout#define DVS_STDERR stderr/*断言错误的输出,文件名,行号,函数名 */#define DVS_ASSERT_ERROR( file_name, line_no, func_name ) do \{ \ fprintf( DVS_STDERR, "\nAssert failed: %s, line %u, func: %s\n", \ file_name, line_no, func_name ); \} while( 0 )/*条件判断的断言*/#define DVS_ASSERT( condition ) do \{ \ if( !(condition) ) \ { \ DVS_ASSERT_ERROR( __FILE__, __LINE__, __PRETTY_FUNCTION__); \ } \} while( 0 )/*调试定位当前位置*/#define DVS_POS fprintf( STDOUT, "\nPos: %s, line %u\n", __FILE__, __LINE__ )#define DVS_INFO( format, args... ) \{ \ if( 1 == DVS_ERROR_FLAG ) \ { \ fprintf( DVS_STDOUT, "[%s : %u] ", __FILE__, __LINE__ ); \ fprintf( DVS_STDOUT, format, ##args ); \ fprintf( DVS_STDOUT, "\n" ); \ } \}/*Error信息输出*/#define DVS_ERROR( format, args... ) do \{ \ if( 1 == DVS_ERROR_FLAG ) \ { \ fprintf( DVS_STDERR, "\n[Error]: " ); \ DVS_INFO( format, ##args ); \ } \} while( 0 )/*Warning 信息输出*/#define DVS_WARNING( format, args... ) do \{ \ if( 1 == DVS_WARING_FLAG ) \ { \ fprintf( DVS_STDOUT, "\n[Waring]: " ); \ DVS_INFO( format, ##args ); \ } \} while( 0 )/*Alert 信息输出*/#define DVS_ALERT( format, args... ) do \{ \ if( 1 == DVS_ALERT_FLAG ) \ { \ fprintf( DVS_STDOUT, "\n[Alert]: " ); \ DVS_INFO( format, ##args ); \ } \} while( 0 )/*Debug 信息输出*/#define DVS_DEBUG( format, args... ) do \{ \ if( 1 == DVS_DEBUG_FLAG ) \ { \ fprintf( DVS_STDOUT, "\n[Debug]: " ); \ DVS_INFO( format, ##args ); \ } \} while( 0 )/*Log 信息输出*/#define DVS_LOG( format, args... ) do \{ \ if( 1 == DVS_LOG_FLAG ) \ { \ time( &timep ); \ pLocalTime = localtime( &timep ); \ fprintf( DVS_STDOUT, "\n%d/%d/%d ", ( 1900 + pLocalTime->tm_year ), \ ( 1 + pLocalTime->tm_mon ), pLocalTime->tm_mday ); \ fprintf( DVS_STDOUT, "%d:%d:%d : [Log]", pLocalTime->tm_hour, \ pLocalTime->tm_min, pLocalTime->tm_sec ); \ DVS_INFO( format, ##args ); \ } \} while( 0 )#endif /*#ifndef DEBUG_H*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -