欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++ Easylogging++日志庫配置使用超詳細講解

 更新時間:2022年11月10日 11:23:51   作者:HW140701  
這篇文章主要介紹了C++ Easylogging++日志庫配置使用,Easylogging++是用于C++應(yīng)用程序的單頭高效日志庫。它非常強大,高度可擴展并且可以根據(jù)用戶的要求進行配置

Easylogging++

Easylogging++是一個只有單個頭文件的開源跨平臺日志庫,擁有簡單易集成,速度極快,線程安全,高效并可配置可擴展等等優(yōu)點,現(xiàn)在也是我的主力日志庫。

下載Easylogging++

Github地址:https://github.com/amrayn/easyloggingpp

從Githu下載Easylogging++,下載下來只有兩個文件,easylogging++.heasylogging++.cc。

在VS中配置Easylogging++

右鍵項目-屬性-C+±常規(guī)-附加包含項目,添加easylogging++.h所在目錄

easylogging++.cc添加到項目中。

使用Easylogging++

(1) 包含頭文件

// easylogging++
#include "easylogging++.h"
#define ELPP_THREAD_SAFE

(2) 初始化Easylogging++

INITIALIZE_EASYLOGGINGPP

(3) 設(shè)置日志輸出配置

static void InitEasyloggingPP()
{
	el::Configurations conf;
	// 啟用日志
	conf.setGlobally(el::ConfigurationType::Enabled, "true");
	//設(shè)置日志文件目錄以及文件名
	conf.setGlobally(el::ConfigurationType::Filename, "log\\log_%datetime{%Y%M%d %H%m%s}.log");
	//設(shè)置日志文件最大文件大小
	conf.setGlobally(el::ConfigurationType::MaxLogFileSize, "20971520");
	//是否寫入文件
	conf.setGlobally(el::ConfigurationType::ToFile, "true");
	//是否輸出控制臺
	conf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
	//設(shè)置日志輸出格式
	conf.setGlobally(el::ConfigurationType::Format, "[%datetime] [%loc] [%level] : %msg");
	//設(shè)置日志文件寫入周期,如下每100條刷新到輸出流中
	conf.setGlobally(el::ConfigurationType::LogFlushThreshold, "100");
	//設(shè)置配置文件
	el::Loggers::reconfigureAllLoggers(conf);
}

(4) 示例程序

// easylogging++
#include "easylogging++.h"
#define ELPP_THREAD_SAFE
INITIALIZE_EASYLOGGINGPP
static void InitEasyloggingPP()
{
	el::Configurations conf;
	// 啟用日志
	conf.setGlobally(el::ConfigurationType::Enabled, "true");
	//設(shè)置日志文件目錄以及文件名
	conf.setGlobally(el::ConfigurationType::Filename, "log\\log_%datetime{%Y%M%d %H%m%s}.log");
	//設(shè)置日志文件最大文件大小
	conf.setGlobally(el::ConfigurationType::MaxLogFileSize, "20971520");
	//是否寫入文件
	conf.setGlobally(el::ConfigurationType::ToFile, "true");
	//是否輸出控制臺
	conf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
	//設(shè)置日志輸出格式
	conf.setGlobally(el::ConfigurationType::Format, "[%datetime] [%loc] [%level] : %msg");
	//設(shè)置日志文件寫入周期,如下每100條刷新到輸出流中
	conf.setGlobally(el::ConfigurationType::LogFlushThreshold, "100");
	//設(shè)置配置文件
	el::Loggers::reconfigureAllLoggers(conf);
}
int main()
{
	InitEasyloggingPP();
	LOG(INFO) << "Hello World";
}

 

到此這篇關(guān)于C++ Easylogging++配置使用超詳細講解的文章就介紹到這了,更多相關(guān)C++ Easylogging++內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論