C++ 日志库EasyLogging++

github下载链接 https://github.com/amrayn/easyloggingpp

1、将easylogging++.h和easylogging++.cc加入项目中

2、配置文件log.cfg

* 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:
	ENABLED  				=   false
	
* DEBUG:
    FILENAME                =   "log\\debug_log_%datetime{%Y%M%d}.log"
	
* FATAL:
    ENABLED                 =   false
	
* ERROR:
    FILENAME                =   "log\\error_log_%datetime{%Y%M%d}.log"
	
* WARNING:
    ENABLED                 =   false
	
* INFO:
    FILENAME                =   "log\\info_log_%datetime{%Y%M%d}.log"
	
* VERBOSE:
    ENABLED                 =   false

3、编码测试

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

//初始化
INITIALIZE_EASYLOGGINGPP

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

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

    system("pause");

    return 0;
}

4、在windows平台下,此库会在工作目录下默认生成一个myeasylog.log的文件可以通过宏定义去掉

C++ 日志库EasyLogging++_第1张图片

 

你可能感兴趣的:(c++,c++)