当前位置:网站首页>Implementation of Muduo asynchronous logging
Implementation of Muduo asynchronous logging
2022-07-03 13:53:00 【yolo_ yyh】
Catalog
Two 、 The destination of the log
3、 ... and 、 Multithreaded asynchronous log implementation
muduo It's for Chen Shuo's personal use C++ Developed a network library , The code is of great learning value , The summary comes from books 《Linux Multithreaded server-side programming 》, Also written by Chen Shuo , Can cooperate with github Use code together .
muduo github website :https://github.com/chenshuo/muduo
One 、 Log level and format
TRACE、DEBUG、INFO、WARN、ERROR、FATAL, The default level is obtained from the environment variable , To adjust the level, you only need to call Logger::setLogLevel() that will do ;
muduo The format of the log message is as follows :

The date and time in the timestamp string are cached , Multiple logs within one second only need to reformat the microsecond part .
Two 、 The destination of the log
Write to a local file .
Rolling condition : File size and time , For program crash , The log cannot flush To hard disk ,muduo On a regular basis ( every other 3 second ) Log the buffer flush To hard disk , And every log message in memory has cookie( The address of a function ), This can be done in core dump Find in the file cookie You can find messages that haven't been written to the disk yet .
3、 ... and 、 Multithreaded asynchronous log implementation
(1) characteristic
Each process writes only one log file , Use a background thread to collect log information , And write the log file , Other business threads just send log messages to this background thread .
(2) Concrete realization
Double buffering technology : Prepare two pieces buffer,A、B, The front end is responsible for buffer A Fill in the data , The back end is responsible for buffer B The data for is written to the file , When buffer A After full , In exchange for A and B, Let the back end bufferA The data for is written to the file , The front end continues bufferB Fill in the new message , So back and forth .
In order to write the log to the file in time , Even if buffer A Not full , Also every 3 Seconds for swap write operation .
When the front-end write frequency is not high :

When the front-end write frequency is high :

Front end write frequency is too high , When messages are dense :

边栏推荐
- 双向链表(我们只需要关注插入和删除函数)
- Go language unit test 3: go language uses gocovey library to do unit test
- Leetcode-1175. Prime Arrangements
- 常见的几种最优化方法Matlab原理和深度分析
- IBEM 数学公式检测数据集
- [机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
- Unity EmbeddedBrowser浏览器插件事件通讯
- pytorch 载入历史模型时更换gpu卡号,map_location设置
- Thrift threadmanager and three monitors
- Record 405 questions about bank callback post request
猜你喜欢
![[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心

Several common optimization methods matlab principle and depth analysis

使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2

The solution of Chinese font garbled code in keil5

The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can

Go language web development series 27: Gin framework: using gin swagger to implement interface documents

Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
![Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:

logback日志的整理

MySQL installation, uninstallation, initial password setting and general commands of Linux
随机推荐
Field problems in MySQL
Use and design of Muduo buffer class
Richview trvstyle liststyle list style (bullet number)
物联网毕设 --(STM32f407连接云平台检测数据)
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
KEIL5出现中文字体乱码的解决方法
JS convert pseudo array to array
The network card fails to start after the cold migration of the server hard disk
JSON serialization case summary
Mastering the cypress command line options is the basis for truly mastering cypress
Go 1.16.4: purpose of go mod tidy
记录关于银行回调post请求405 问题
Libuv Library - Design Overview (Chinese version)
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
编程内功之编程语言众多的原因
Qt学习22 布局管理器(一)
Golang — template
Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
Ocean CMS vulnerability - search php