当前位置:网站首页>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 :
边栏推荐
- Leetcode-1175. Prime Arrangements
- Golang — template
- Implementation of Muduo accept connection, disconnection and sending data
- The reasons why there are so many programming languages in programming internal skills
- Qt学习17 对话框及其类型
- Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
- Open PHP error prompt under Ubuntu 14.04
- RichView TRVStyle ListStyle 列表样式(项目符号编号)
- Summary of common error reporting problems and positioning methods of thrift
- Ocean CMS vulnerability - search php
猜你喜欢
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
双向链表(我们只需要关注插入和删除函数)
研发团队资源成本优化实践
Go language unit test 3: go language uses gocovey library to do unit test
Qt学习17 对话框及其类型
SQL Injection (GET/Search)
Qt学习25 布局管理器(四)
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
[技術發展-24]:現有物聯網通信技術特點
随机推荐
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
Leetcode-1175. Prime Arrangements
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
编程内功之编程语言众多的原因
Leetcode-1175.Prime Arrangements
栈应用(平衡符)
Go 1.16.4: manage third-party libraries with Mod
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Screenshot of the operation steps of upload labs level 4-level 9
项目协作的进度如何推进| 社区征文
Libuv库 - 设计概述(中文版)
从零开始的基于百度大脑EasyData的多人协同数据标注
Swiftui development experience: the five most powerful principles that a programmer needs to master
Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
Depth and breadth first traversal of tree (regardless of binary tree)
[redis] cache warm-up, cache avalanche and cache breakdown
JS convert pseudo array to array
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
JVM系列——概述,程序计数器day1-1
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2