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;
}
复制代码

输出:

 

posted @   He_LiangLiang  阅读(2285)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示