easyloggingpp C++日志三方库推荐

easyloggingpp
github地址:https://github.com/amrayn/easyloggingpp
gitee地址:https://gitee.com/yingge2017/easyloggingpp

是一个开源的C++日志库。库只有两个源文件,相比较log4cpp和glog等日志库来说更加轻便,不用预先编译,但是功能满足日常使用。
目前最新的版本是 v9.96.7 支持C++容器,C++11语法,支持配置文件而且增加了Qt数据文本的支持。


在代码中使用

#include "mainwindow.h"
#include "easylogging++.h"

//初始化
INITIALIZE_EASYLOGGINGPP

int main(int argc, char *argv[]){    

    el::Configurations conf("log.conf");                                
    el::Loggers::reconfigureAllLoggers(conf);
    
    LOG(ERROR)   << "-----error log";    
    LOG(WARNING) << "-----warning log";    
    LOG(INFO)    << "-----info log";
    LOG(TRACE)   << "-----trace log";    
    LOG(DEBUG)   << "-----debug log";

    system("pause");

    return 0;
}



配置文件
GLOBAL结构表示全局日志类型的设置。
不论是TRACE还是DEBUG类型的日志都要先继承GLOBAL结构中的设置,再去遵守各自日志类型标签下的设置。

* GLOBAL:  
    ENABLED                 =   true  
    TO_FILE                 =   true  
    TO_STANDARD_OUTPUT      =   true  
    FORMAT                  =   "[%level | %datetime] | %msg"  
    FILENAME                =   "log\\log_%datetime{%Y%M%d}.log"  
    MILLISECONDS_WIDTH      =   3  
    PERFORMANCE_TRACKING    =   false  
    MAX_LOG_FILE_SIZE       =   1048576  
    LOG_FLUSH_THRESHOLD     =   0  
      
* TRACE:  
    FILENAME                =   "log\\trace_log_%datetime{%Y%M%d}.log"  
      
* DEBUG:  
    FILENAME                =   "log\\debug_log_%datetime{%Y%M%d}.log"  
      
* FATAL:  
    ENABLED                 =   false  
      
* ERROR:  
    FILENAME                =   "log\\error_log_%datetime{%Y%M%d}.log"  
      
* WARNING:  
    FILENAME                =   "log\\warning_log_%datetime{%Y%M%d}.log"  
      
* INFO:  
    FILENAME                =   "log\\info_log_%datetime{%Y%M%d}.log"  
      
* VERBOSE:  
    ENABLED                 =   false  


输出为

21:29:12: Starting D:\workspace\build-easyloggingpp_demo-Desktop_Qt_5_12_0_MinGW_64_bit-Debug\debug\easyloggingpp_demo.exe...
[ERROR | 2020-05-06 21:29:13,355] | -----error log
[WARNING | 2020-05-06 21:29:13,355] | -----warning log
[INFO | 2020-05-06 21:29:13,355] | -----info log
[TRACE | 2020-05-06 21:29:13,356] | -----trace log
[DEBUG | 2020-05-06 21:29:13,356] | -----debug log
请按任意键继续. . . 
t

输出日志文件

easyloggingpp C++日志三方库推荐_第1张图片

 

 

easyloggingpp C++日志三方库推荐_第2张图片

你可能感兴趣的:(我的公众号:程序员进阶)