当前位置:网站首页>Easylogging + + log Library
Easylogging + + log Library
2022-04-22 07:51:00 【Happinessคิดถึง】
I recently learned about this powerful log Library , It's really fragrant .
brief introduction
Easylogging++ Is used for C++ Single header efficient log library for applications . It's very powerful , Highly scalable and can be configured according to user requirements . It provides the ability to write your own receiver ( Through the called The characteristics of LogDispatchCallback). The library is currently github And hundreds of open source projects on other open source source control and management sites .
Reference resources
GitHub
https://github.com/amrayn/easyloggingpp
https://www.cnblogs.com/bokeyuan-dlam/articles/7635003.html
Use configuration

I recommend using the configuration log file for configuration . Create a new one easylogging.conf file
Configuration interpretation :

* GLOBAL:
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
FORMAT = "%datetime %level [%fbase|%line] %msg"
FILENAME = "C:\\logs\\%datetime{%Y%M%d}.log"
MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 20048576
LOG_FLUSH_THRESHOLD = 0
* TRACE:
* DEBUG:
* FATAL:
* ERROR:
* WARNING:
* INFO:
* VERBOSE:
When the project is initialized, just load the configuration file .
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
void initLog()
{
// The flag must be set LoggingFlag::StrictLogFileSizeCheck
// otherwise , In profile MAX_LOG_FILE_SIZE = 20048576 Don't take effect
// Mode one : Load local conf The way
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
// Configuration file path address
el::Configurations conf("C:\\esaylogging.conf");
// One can be set separately logger Configuration of
//el::Loggers::reconfigureLogger("default", conf);
/// You can also set all logger Configuration of
el::Loggers::reconfigureAllLoggers(conf);
// Mode two : Load default configuration
el::Configurations conf;
conf.setToDefault();
conf.setGlobally(el::ConfigurationType::Format, "%datetime %level [%fbase|%line] %msg");
conf.setGlobally(el::ConfigurationType::Filename, path+"\\%datetime{%Y%M%d}.log");
conf.setGlobally(el::ConfigurationType::Enabled, "true");
conf.setGlobally(el::ConfigurationType::ToFile, "true");
conf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
el::Loggers::reconfigureAllLoggers(conf);
}
int main(int argc, char *argv[])
{
initLog();
LOG(INFO) << "My First Easylog!";
return 0;
}
Finally, you can use the log happily .
effect

Be able to locate the output log of your code . Very fragrant, very fragrant .
Disable default generated myeasylog.log file
stay easylogging++.cc Add the following macro definition
#define ELPP_NO_DEFAULT_LOG_FILE
LINFO << Class name ;
main Function can be used in LINFO Like other built-in data types, it outputs myClass, Will output log as follows :
1 4:32:47.031 INFO MyClass name is Awesome class
If you want to output STL Of string,wstring Class and container :vector,list,map,set etc. , Then just define the macro :
#define _ELPP_STL_LOGGING
If you want to support QT Class output of Library , You need to define a macro :
#define _ELPP_QT_LOGGING
版权声明
本文为[Happinessคิดถึง]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220623156244.html
边栏推荐
猜你喜欢

Dependency conflict finding and resolution (taking easypoi as an example, nosuchmethoderror or NoClassDefFoundError appears)

Operation of SM2 encryption signature verification
![Stm32外设篇 [二] I2C](/img/98/13b749c8c1edc038b70e62389df9fe.png)
Stm32外设篇 [二] I2C

Unity遮罩 反向遮罩实现
![Stm32外设篇 [四] RCC](/img/e1/e81d1e6017bebc87690227a7aa5f99.png)
Stm32外设篇 [四] RCC

【TCP/IP 五 ICMP】

Problem A: 人脸识别

数据库-Mysql--Navicat 导入sql出现错误 1067 - Invalid default value for ‘payDate‘

Wechat payment and receipt version docking
![单片机原理[一] 学好单片机必会的五张图](/img/49/bf1cdb477622375dd558e4c6b1cf60.jpg)
单片机原理[一] 学好单片机必会的五张图
随机推荐
Information System Project Manager --- Chapter IV examination questions of overall project management over the years
【通信接口 - CAN总线】
Thread pool usage
QT学习汇总
Unity知识点(UGUI)
动态库总结
2021-08-11
数据库-Sql--模拟插入大量数据、导入/出数据库脚本、时间戳转换以及数据库基础知识
Rt-thread [三] link.lds链接脚本详解
函数式接口@FunctionalInterface的使用说明
同一个类中@Transactional 事务传播
Database advanced query
ActiveMQ的消息模式——队列模式
寻找3d地图上没有障碍物的点
Rt-thread [一] 创建工程
关于SM2加密验签的操作
C#程序初解析 及编写注意事项
JS realizes web page special effects on PC and mobile terminals
Information System Project Manager - Chapter IV overall project management
Distinction