1. 程式人生 > >使用easylogging++進行日誌輸出

使用easylogging++進行日誌輸出

#include <iostream>
#include <fstream>
//支援多執行緒
#define ELPP_THREAD_SAFE
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
using namespace std;

int main(int argc, char* argv[])
{
    std::cout << "test openh264" << std::endl;
    int nPos = 1024*1024*2;

    el::Configurations defaultConf;
    defaultConf.setToDefault();
    //設定最大檔案大小
    defaultConf.setGlobally(el::ConfigurationType::MaxLogFileSize, "2097152");
    //是否寫入檔案
    defaultConf.setGlobally(el::ConfigurationType::ToFile, "true");
    //是否輸出控制檯
    defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
    //設定配置檔案
    el::Loggers::reconfigureLogger("default", defaultConf);
    
    /// 防止Fatal級別日誌中斷程式
    el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
    
    /// 選擇劃分級別的日誌    
    el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);

    /// 設定級別門閥值,修改引數可以控制日誌輸出
    el::Loggers::setLoggingLevel(el::Level::Global);

    LOG(INFO) << "Log using default file" << nPos;

    LOG(TRACE)<< "Log using default file" << nPos;
    LOG(DEBUG)<< "Log using default file" << nPos;
    LOG(FATAL)<< "Log using default file" << nPos;
    LOG(ERROR)<< "Log using default file" << nPos;
    LOG(WARNING)<< "Log using default file" << nPos;
    LOG(INFO)<< "Log using default file" << nPos;
    VLOG(0)<< "Log using default file" << nPos;
    return 0;
}