easylogging 的笔记

news2024/9/28 23:27:07

学习总结

应用在c++的工程里
easylog是一个用于记录日志的工具,其中分出了7种级别:分别是INFO;DEBUG;WARNING;TRACE;VERBOSE;ERROR;FATAL。其中FATAL这个log的输出会导致程序运行的退出:“Very severe error event that will presumably lead the application to abort.”通过配置log.conf文件,可以实现输出日志的格式、日志存放目录、存放方式(按照日志级别多文件存放,还是单文件汇总)。

通过配置log.conf文件,可以实现
输出log的格式、log存放目录、存放方式(按照log级别多文件存放,还是单文件汇总)

学习过程记录

https://www.cnblogs.com/linxmouse/p/9101504.html

发现林哥给的文档中提供了

请添加图片描述

新发现

//这个可以直接调调试窗口的命令欸,啧啧啧好东西

system(“ls”);

测试例程

按照下面这个例程跑出来的结果,只生成了一个log文件,所有的log都是打印在这里的。

请添加图片描述

main.cpp

#include "easylogging.h"

INITIALIZE_EASYLOGGINGPP

void easylogginginit()
{
    // 加载配置文件,构造一个配置器对象
    el::Configurations conf( "../../log.conf" );
    // 重新配置一个单一日志记录器
    el::Loggers::reconfigureLogger( "default", conf );
    // 用配置文件配置所有的日志记录器
    el::Loggers::reconfigureAllLoggers( conf );
}

int main()
{
    easylogginginit();
    
    LOG(TRACE)   << "***** trace log  *****";
    LOG(DEBUG)   << "***** debug log  *****";
    LOG(ERROR)   << "***** error log  *****";
    LOG(WARNING) << "***** warning log  *****";
    LOG(INFO)    << "***** info log  *****";
    // LOG(FATAL)   << "***** fatal log  *****";//这个会导致程序退出运行
    LOG(INFO)    << "***** info log123  *****";

    //这个可以直接调调试窗口的命令欸,啧啧啧好东西
    system("ls");
    return 0;
}

希望的可以实现是不同类型的log信息分门别类的放在不同的文件夹

这样配置就会在可执行文件当前目录下的log文件夹中生成对应的log文件,前提/log目录已经存在

请添加图片描述

log.conf配置
* GLOBAL:
    FORMAT                  =   "%datetime:[%level]     %msg"
    ENABLED                 =   true
    TO_FILE                 =   true
    TO_STANDARD_OUTPUT      =   false  
    PERFORMANCE_TRACKING    =   false    
    FILENAME                =   "log/log_%datetime{%Y%M%d}.log"
    MAX_LOG_FILE_SIZE       =   209715200 ## Throw log files away after 2097152 2MB / 209715200 200MB / 4398046511104 1GB 
* INFO:
	FORMAT                  =   "%datetime:[%level]    %msg"
    FILENAME                =   "log/debug_%datetime{%Y%M%d%H}.log"
* DEBUG:
    FILENAME                =   "log/debug_log_%datetime{%Y%M%d}.log"
* WARNING:
	FORMAT                  =   "%datetime:[%level]   %msg"
    FILENAME                =   "log/warn_%datetime{%Y%M%d%H}.log"
* TRACE:
    FILENAME                =   "log/trace_log_%datetime{%Y%M%d}.log"
* VERBOSE:
    FORMAT                  =   "%datetime{%d/%M/%y} | %level-%vlevel | %msg"
* ERROR:
    FILENAME                =   "log/error_%datetime{%Y%M%d%H}.log"
#出现这个log会在终端上输出打印出来
    TO_STANDARD_OUTPUT      =   true
* FATAL:
    FILENAME                =   "log/fatal_%datetime{%Y%M%d%H}.log"
    TO_STANDARD_OUTPUT      =   true

屏蔽 GLOBAL:的这句话,FILENAME那么全部log都会打印到myeasylog.log的文件夹中*

请添加图片描述

#出现这个log会在终端上输出打印出来

TO_STANDARD_OUTPUT = true

error 的log会在cli窗口额外输出

请添加图片描述

附上一段官方文档配置

Level级别

In order to start configuring your logging library, you must understand severity levels. Easylogging++ deliberately does not use hierarchical logging in order to fully control what’s enabled and what’s not. That being said, there is still option to use hierarchical logging using LoggingFlag::HierarchicalLogging. Easylogging++ has following levels (ordered for hierarchical levels)

LevelDescription
GlobalGeneric level that represents all levels. Useful when setting global configuration for all levels.
代表所有级别的通用级别。在为所有级别设置全局配置时很有用。
TraceInformation that can be useful to back-trace certain events - mostly useful than debug logs.
可用于回溯某些事件的信息-大多数信息比调试日志有用。
DebugInformational events most useful for developers to debug application. Only applicable if NDEBUG is not defined (for non-VC++) or _DEBUG is defined (for VC++).
信息事件对开发人员调试应用程序最有用。仅在未定义NDEBUG(对于非VC ++)或_DEBUG(对于VC ++)时适用。
FatalVery severe error event that will presumably lead the application to abort.
非常严重的错误事件,可能会导致应用程序中止。
ErrorError information but will continue application to keep running.
错误信息,但将继续使应用程序继续运行。
WarningInformation representing errors in application but application will keep running.
表示应用程序错误的信息,但应用程序将继续运行。
InfoMainly useful to represent current progress of application.
主要用于表示当前的应用进度。
VerboseInformation that can be highly useful and vary with verbose logging level. Verbose logging is not applicable to hierarchical logging.
信息非常有用,并且随着详细的日志记录级别而变化。详细日志记录不适用于分层日志记录。
UnknownOnly applicable to hierarchical logging and is used to turn off logging completely.
仅适用于分层日志记录,用于完全关闭日志记录。

Configure

Easylogging++ is easy to configure. There are three possible ways to do so,

  • Using configuration file
  • Using el::Configurations class
  • Using inline configuration
Using Configuration File

Configuration can be done by file that is loaded at runtime by Configurations class. This file has following format;

* LEVEL:
  CONFIGURATION NAME  = "VALUE" ## Comment
  ANOTHER CONFIG NAME = "VALUE"

Level name starts with a star (*) and ends with colon (😃. It is highly recommended to start your configuration file with Global level so that any configuration not specified in the file will automatically use configuration from Global. For example, if you set Filename in Global and you want all the levels to use same filename, do not set it explicitly for each level, library will use configuration value from Global automatically.
Following table contains configurations supported by configuration file.

Configuration NameTypeDescription
EnabledboolDetermines whether or not corresponding level for logger is enabled. You may disable all logs by using el::Level::Global
确定是否启用了记录器的相应级别。您可以通过使用禁用所有日志el::Level::Global
To_FileboolWhether or not to write corresponding log to log file
是否将相应的日志写入日志文件
To_Standard_OutputboolWhether or not to write logs to standard output e.g, terminal or command prompt
是否将日志写入标准输出,例如终端或命令提示符
Formatchar*Determines format/pattern of logging for corresponding level and logger.
确定相应级别和记录器的记录格式/模式。
Filenamechar*Determines log file (full path) to write logs to for corresponding level and logger
确定日志文件(完整路径)以将日志写入相应级别的日志记录器
Subsecond_PrecisionuintSpecifies subsecond precision (previously called ‘milliseconds width’). Width can be within range (1-6)
指定亚秒级精度(以前称为“毫秒宽度”)。宽度可以在(1-6)范围内
Performance_TrackingboolDetermines whether or not performance tracking is enabled. This does not depend on logger or level. Performance tracking always uses ‘performance’ logger unless specified
确定是否启用性能跟踪。这与记录器或级别无关。除非指定,否则性能跟踪始终使用“性能”记录器
Max_Log_File_Sizesize_tIf log file size of corresponding level is >= specified size, log file will be truncated.
如果相应级别的日志文件大小> =指定大小,则日志文件将被截断。
Log_Flush_Thresholdsize_tSpecifies number of log entries to hold until we flush pending log data
指定在刷新未完成的日志数据之前要保留的日志条目数

Please do not use double-quotes anywhere in comment, you might end up in unexpected behaviour.

Sample Configuration File

* GLOBAL:
   FORMAT               =  "%datetime %msg"
   FILENAME             =  "/tmp/logs/my.log"
   ENABLED              =  true
   TO_FILE              =  true
   TO_STANDARD_OUTPUT   =  true
   SUBSECOND_PRECISION  =  6
   PERFORMANCE_TRACKING =  true
   MAX_LOG_FILE_SIZE    =  2097152 ## 2MB - Comment starts with two hashes (##)
   LOG_FLUSH_THRESHOLD  =  100 ## Flush after every 100 logs
* DEBUG:
   FORMAT               = "%datetime{%d/%M} %func %msg"
Explanation

Configuration file contents in above sample is straightforward. We start with GLOBAL level in order to override all the levels. Any explicitly defined subsequent level will override configuration from GLOBAL. For example, all the levels except for DEBUG have the same format, i.e, datetime and log message. For DEBUG level, we have only date (with day and month), source function and log message. The rest of configurations for DEBUG are used from GLOBAL. Also, notice {%d/%M} in DEBUG format above, if you do not specify date format, default format is used. Default values of date/time is %d/%M/%Y %h:%m:%s,%g For more information on these format specifiers, please refer to Date/Time Format Specifier section below

ERROR的效果

会具体打印出代码的位子

2021-03-05 09:31:36,584:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:0
2021-03-05 09:31:37,085:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:1
2021-03-05 09:31:37,586:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:2
2021-03-05 09:31:38,087:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:3
2021-03-05 09:31:38,588:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:3
2021-03-05 09:31:39,089:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:4
2021-03-05 09:31:39,591:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:5
2021-03-05 09:31:40,092:[ERROR] VOID DataCollecter::LoopFuncList(std::vector<IOFunctionList>)[925] Data collection failed key is:6

如何设置log存放路径

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1323314.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

剑指 Offer(第2版)面试题 41:数据流的中位数

剑指 Offer&#xff08;第2版&#xff09;面试题 41&#xff1a;数据流的中位数 剑指 Offer&#xff08;第2版&#xff09;面试题 41&#xff1a;数据流的中位数解法1&#xff1a;优先队列解法2&#xff1a;有序集合 双指针 剑指 Offer&#xff08;第2版&#xff09;面试题 41…

控制理论simulink+matlab

这里写目录标题 根轨迹二级目录三级目录 根轨迹 z [-1]; %开环传递函数的零点 p [0 -2 -3 -4]; %开环传递函数的系统极点 k 1; %开环传递函数的系数&#xff0c;反映在比例上 g zpk(z,p,k); %生成开环传递函数%生成的传递函数如下 % (s1) % -------------…

【HarmonyOS开发】ArkUI中的自定义弹窗

弹窗是一种模态窗口&#xff0c;通常用来展示用户当前需要的或用户必须关注的信息或操作。在弹出框消失之前&#xff0c;用户无法操作其他界面内容。ArkUI 为我们提供了丰富的弹窗功能&#xff0c;弹窗按照功能可以分为以下两类&#xff1a; 确认类&#xff1a;例如警告弹窗 Al…

GitBook安装及使用——使用 Markdown 创建你自己的博客网站和电子书

目录 前言一、依赖环境二、gitbook安装使用1.安装 gitbook-cli2.安装 gitbook3.Gitbook初始化4.创建你的文章5.修改 SUMMARY.md 和 README.md6.编译生成静态网页7.运行以便在浏览器预览8.运行效果 前言 GitBook是一个命令行工具&#xff0c;用于使用 Markdown 构建漂亮的博客网…

npm login报错:Public registration is not allowed

npm login报错:Public registration is not allowed 1.出现场景2.解决 1.出现场景 npm login登录时,出现 2.解决 将自己的npm镜像源改为npm的https://registry.npmjs.org/这个&#xff0c;解决&#xff01;

鸿蒙4.0核心技术-WebGL开发

场景介绍 WebGL主要帮助开发者在前端开发中完成图形图像的相关处理&#xff0c;比如绘制彩色图形等。 接口说明 表1 WebGL主要接口列表 接口名描述canvas.getContext获取canvas对象上下文。webgl.createBuffer(): WebGLBuffernullwebgl.bindBuffer(target: GLenum, buffer: …

服务器数据恢复-EMC存储raid5磁盘物理故障离线的数据恢复案例

服务器数据恢复环境&故障&#xff1a; 一台emc某型号存储服务器&#xff0c;存储服务器上组建了一组raid5磁盘阵列&#xff0c;阵列中有两块磁盘作为热备盘使用。存储服务器在运行过程中有两块磁盘出现故障离线&#xff0c;但是只有一块热备盘激活&#xff0c;最终导致该ra…

Gin之GORM多表关联查询(多对多;自定义预加载SQL)

数据库三个,如下: 注意:配置中间表的时候,表设计层面最好和配置的其他两张表契合,例如其他两张表为fate内的master和slave;要整合其对应关系的话,设计中间表的结构为master_id和slave_id最好(不然会涉及重写外键的操作) 重写外键(介绍) 对于 many2many 关系,连接表…

智能优化算法应用:基于黑寡妇算法3D无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用&#xff1a;基于黑寡妇算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用&#xff1a;基于黑寡妇算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.黑寡妇算法4.实验参数设定5.算法结果6.参考文…

Jenkins Docker Cloud在Linux应用开发CI中的实践

Jenkins Docker Cloud在Linux应用开发CI中的实践 背景 通过代码提交自动触发CI自动构建、编译、打包是任何软件开发组织必不可少的基建&#xff0c;可以最大程度保证产物的一致性&#xff0c;方便跨组跨部门协作&#xff0c;代码MR等。 Docker在流水线中越来越重要&#xff…

iPhone手机开启地震预警功能

iPhone手机开启地震预警功能 地震预警告警开启方式 地震预警 版权&#xff1a;成都高新减灾研究所 告警开启方式

蜘点云原生之 KubeSphere 落地实践过程

作者&#xff1a;池晓东&#xff0c;蜘点商业网络服务有限公司技术总监&#xff0c;从事软件开发设计 10 多年&#xff0c;喜欢研究各类新技术&#xff0c;分享技术。 来源&#xff1a;本文由 11 月 25 日广州站 meetup 中讲师池晓东整理&#xff0c;整理于该活动中池老师所分享…

YOLOv8改进 | 主干篇 | 轻量级网络ShuffleNetV2(附代码+修改教程)

一、本文内容 本文给大家带来的改进内容是ShuffleNetV2&#xff0c;这是一种为移动设备设计的高效CNN架构。其在ShuffleNetV1的基础上强调除了FLOPs之外&#xff0c;还应考虑速度、内存访问成本和平台特性。(我在YOLOv8n上修改该主干降低了GFLOPs,但是参数量还是有一定上涨&am…

【Docker】基础篇

文章目录 Docker为什么出现容器和虚拟机关于虚拟机关于Docker二者区别&#xff1a; Docker的基本组成相关概念-镜像&#xff0c;容器&#xff0c;仓库安装Docker卸载docker阿里云镜像加速docker run的原理**为什么容器比虚拟机快**Docker的常用命令1.帮助命令2.镜像相关命令3.容…

C语言—每日选择题—Day51

第一题 1. 对于函数void f(int x);&#xff0c;下面调用正确的是&#xff08;&#xff09; A&#xff1a;int y f(9); B&#xff1a;f(9); C&#xff1a;f( f(9) ); D&#xff1a;xf(); 答案及解析 B 函数调用要看返回值和传参是否正确&#xff1b; A&#xff1a;错误&#xf…

【ArcGIS微课1000例】0081:ArcGIS指北针乱码解决方案

问题描述&#xff1a; ArcGIS软件在作图模式下插入指北针&#xff0c;出现指北针乱码&#xff0c;如下图所示&#xff1a; 问题解决 下载并安装字体&#xff08;配套实验数据包0081.rar中获取&#xff09;即可解决该问题。 正常的指北针选择器&#xff1a; 专栏介绍&#xff…

Hadoop3.x完全分布式模式下slaveDataNode节点未启动调整

目录 前言 一、问题重现 1、查询Hadoop版本 2、集群启动Hadoop 二、问题分析 三、Hadoop3.x的集群配置 1、停止Hadoop服务 2、配置workers 3、从节点检测 4、WebUI监控 总结 前言 在大数据的世界里&#xff0c;Hadoop绝对是一个值得学习的框架。关于Hadoop的知识&…

elementui中的el-table,当使用fixed属性时,table主体会遮挡住滚动条的大半部分,导致很难选中。

情况&#xff1a; 解决&#xff1a; el-table加个类&#xff0c;这里取为class"table" 然后是样式部分&#xff1a; <style scoped lang"scss"> ::v-deep.table {// 滚动条高度调整::-webkit-scrollbar {height: 15px;}// pointer-events 的基本信…

一款电压检测LVD

一、基本概述 The TX61C series devices are a set of three terminal low power voltage detectors implemented in CMOS technology. Each voltage detector in the series detects a particular fixed voltage ranging from 0.9V to 5.0V. The voltage detectors consist…

使用Axure的中继器的交互动作解决增删改查h

&#x1f3ac; 艳艳耶✌️&#xff1a;个人主页 &#x1f525; 个人专栏 &#xff1a;《产品经理如何画泳道图&流程图》 ⛺️ 越努力 &#xff0c;越幸运 目录 一、中继器的交互 1、什么是中继器的交互 2、Axure中继器的交互 3、如何使用中继器&#xff1f; 二…