当前位置:网站首页>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 :
边栏推荐
- JVM系列——概述,程序计数器day1-1
- Libuv Library - Design Overview (Chinese version)
- Leetcode-1175.Prime Arrangements
- MySQL 数据处理值增删改
- GoLand 2021.1.1: configure the multi line display of the tab of the open file
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
- Flutter dynamic | fair 2.5.0 new version features
- [how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
- SQL Injection (POST/Search)
- Qt学习24 布局管理器(三)
猜你喜欢
[sort] bucket sort
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
Golang - command line tool Cobra
logback日志的整理
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Go language unit test 3: go language uses gocovey library to do unit test
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
There is nothing new under the sun. Can the meta universe go higher?
Implementation of Muduo accept connection, disconnection and sending data
随机推荐
[technology development-24]: characteristics of existing IOT communication technology
Qt学习19 Qt 中的标准对话框(上)
Go language unit test 4: go language uses gomonkey to test functions or methods
[sort] bucket sort
IBEM mathematical formula detection data set
Leetcode-1175. Prime Arrangements
Red hat satellite 6: better management of servers and clouds
Halcon combined with C # to detect surface defects -- Halcon routine autobahn
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
Dynamic programming 01 knapsack and complete knapsack
Golang — 命令行工具cobra
Asp. Net core1.1 without project JSON, so as to generate cross platform packages
CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
How to promote the progress of project collaboration | community essay solicitation
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
untiy世界边缘的物体阴影闪动,靠近远点的物体阴影正常
Software testing is so hard to find, only outsourcing offers, should I go?