日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網(wǎng)站首頁 編程語言 正文

C++?Easylogging++日志庫配置使用超詳細講解_C 語言

作者:HW140701 ? 更新時間: 2022-12-09 編程語言

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) 設置日志輸出配置

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

?

原文鏈接:https://stubbornhuang.blog.csdn.net/article/details/127532430

欄目分類
最近更新