Linux下面的高效的日志输出
用这里的宏定义,即可非常便捷的实现日志的打印输出。
前提条件:需要支持C++11,下面的链接,告诉你如何升级GCC到7.5来支持C++11
CentOS7 安装 GCC7.5:https://www.cnblogs.com/music-liang/p/12900457.html
#include <iostream> using namespace std; #include <iostream> #include <string> using namespace std; #define DBGDUMP(...) \ {\ printf("FILE:%s,func:%s,Line%d: ", __FILE__, __func__, __LINE__);\ printf(__VA_ARGS__);\ } void test() { cout << "This is the line number " << __LINE__; cout << " of file " << __FILE__ << ".\n"; cout << "Its compilation began " << __DATE__; cout << " at " << __TIME__ << ".\n"; cout << "The compiler gives a " << "__cplusplus value of " << __cplusplus<<endl; cout <<"FILE:"<<__FILE__<<endl; cout <<"function name:"<<__func__<<endl; } int main() { int ret = 1; DBGDUMP("ret=%d \r\n", ret); //日志打印输出 int a=666,b=777; string strC = "henry"; DBGDUMP("a=%d,b=%d,strC:%s \r\n",a,b,strC.c_str()); //日志打印输出,非常便捷 test(); cout << endl; return 0; }
输出:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?