首页 > 系统服务 > 详细

Linux下面的高效的日志输出

时间:2020-08-30 09:27:32      阅读:89      评论:0      收藏:0      [点我收藏+]

 

用这里的宏定义,即可非常便捷的实现日志的打印输出。

前提条件:需要支持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;
}

输出:

技术分享图片

 

Linux下面的高效的日志输出

原文:https://www.cnblogs.com/music-liang/p/13584343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!