目录Easylogging++下载Easylogging++在VS中配置Easylogging++使用Easylogging++Easylogging++ Easylogging++
Easylogging++是一个只有单个头文件的开源跨平台日志库,拥有简单易集成,速度极快,线程安全,高效并可配置可扩展等等优点,现在也是我的主力日志库。
GitHub地址:https://github.com/amrayn/easyloggingpp
从Githu下载Easylogging++,下载下来只有两个文件,easylogging++.h
和easylogging++.cc
。
右键项目-属性-C+±常规-附加包含项目,添加easylogging++.h
所在目录
将easylogging++.cc
添加到项目中。
(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";
}
到此这篇关于c++ Easylogging++配置使用超详细讲解的文章就介绍到这了,更多相关C++ Easylogging++内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: C++Easylogging++日志库配置使用超详细讲解
本文链接: https://www.lsjlt.com/news/171202.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0