outputdebugstring函数的封装
来源:互联网 发布:淘宝v2是什么意思 编辑:程序博客网 时间:2024/05/22 01:53
使用debugview分析问题时,outputdebugstring函数可以在debug和release版本中都显示信息,这比trace更加实用,但前提是你必须将它的参数形式修改成和trace或printf函数一样,下面给出简单修改后的函数形式,并利用宏定义实现日志输出:
int DebugPrintf(LPCTSTR ptzFormat, ...){va_list vlArgs;TCHAR tzText[1024];va_start(vlArgs, ptzFormat);//返回-1说明缓存不够 使用下面方式获取实际所需长度//int iRealSize= _vsntprintf(NULL,0, ptzFormat, vlArgs);int iRet= _vsntprintf(tzText,1024, ptzFormat, vlArgs);if (iRet<0){tzText[1023] = '\0';}OutputDebugString(tzText); va_end(vlArgs);return iRet;}#define LOG_PRINTF DebugPrintf#define CONSTSTR_DEBUG"[DEBUG] "#define CONSTSTR_INFO"[INFO] "#define CONSTSTR_WARNING"[WARNING] "#define CONSTSTR_ERROR"[ERROR] "#define LOGLEVEL_DEBUG1#define LOGLEVEL_INFO2#define LOGLEVEL_WARN3#define LOGLEVEL_ERROR4int AppLogLevel(){static int iLogLevel =-1;if(iLogLevel<0){ iLogLevel = GetPrivateProfileInt(_T("log"),_T("level"),0, _T("log_config.ini"));} return iLogLevel;}#define APPLOG_DEBUG(s,...) { if(AppLogLevel()<=LOGLEVEL_DEBUG){ LOG_PRINTF(CONSTSTR_DEBUG s "\r\n", ##__VA_ARGS__); } }#define APPLOG_INFO(s,...) { if(AppLogLevel()<=LOGLEVEL_INFO) { LOG_PRINTF(CONSTSTR_DEBUG s "\r\n", ##__VA_ARGS__); } }#define APPLOG_WARN(s,...) { if(AppLogLevel()<=LOGLEVEL_WARN) { LOG_PRINTF(CONSTSTR_DEBUG " FILE: " __FILE__ " LINE:%d," s "\r\n",__LINE__, ##__VA_ARGS__); } }#define APPLOG_ERROR(s,...) { if(AppLogLevel()<=LOGLEVEL_ERROR){ LOG_PRINTF(CONSTSTR_DEBUG " FILE: " __FILE__ " LINE:%d," s "\r\n",__LINE__, ##__VA_ARGS__); } }#define MOUDULE_LOG_DEBUG(s,...) APPLOG_DEBUG("[MOUDLE_LOGTEST] " s ,##__VA_ARGS__);int _tmain(int argc, _TCHAR* argv[]){APPLOG_DEBUG("my name is %s ","handsome boy");MOUDULE_LOG_DEBUG("my name is %s ","handsome boy");APPLOG_ERROR("my name is %s ","handsome boy");return 0;}
呵呵,不保证没bug噢
阅读全文
0 0
- outputdebugstring函数的封装
- OutputDebugString 封装
- OutputDebugString函数
- 追逐自己的梦想----------辅助制作第七课:封装调试函数OutputDebugString(),使其可调试任意参数个数
- OutputDebugString完美封装
- OutputDebugString 封装;方便格式化
- 方便的格式化OutputDebugString输出函数
- 方便的格式化OutputDebugString输出函数
- dbgview OutputDebugString输出函数
- (更新)OutputDebugString函数简单封装,实现格式化打印输出(VC++)
- 写了个统一 OutputDebugString 输出的函数
- Microsoft Visual Studio 中printf的替代函数OutputDebugString
- OutputDebugString的用法
- OutputDebugString的BUG
- OutputDebugString的用法
- OutputDebugString
- OutputDebugString
- OutputDebugString
- php命名空间
- 【详细注释】Java->Socket 服务器与客户端的半双工通讯。拥有详细注释,完美诠释。
- FFmpeg源码剖析-通用:ffmpeg_parse_options()
- springMVC的概念及处理流程
- Ext submit时报错 Failed to execute 'appendChild' on 'Node': The new child element is null.
- outputdebugstring函数的封装
- Java:自定义类做key值,需注意什么
- 视频质量评价各种数值---十八个客观测试的方法对比
- _finddata_t结构体用法
- 【备忘】徐老师hadoop hbase zookeeper spark kafka大数据视频教程
- 如何有条件的查询或删除表中的重复记录
- System.MissingMethodException的问题该怎么解决?
- 【U3D】关于 UGUI按钮:Button 以及事件:EventTrigger 的一些经验教训
- 模拟点击