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;
}

輸出:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM