Skip to content

C++ version of synchronous & asynchronous logging system based on multiple design patterns

License

Notifications You must be signed in to change notification settings

ffengc/Multi-Pattern-Logging-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Pattern-Logging-System

C++ version of synchronous & asynchronous logging system based on multiple design patterns

Tip

If you have any questions about the operation and implementation of this project, or if you have better optimization suggestions for this project, you can contact me directly or leave an issue in the repository.

Basic information of the project

This project is mainly to implement a log system, which mainly supports the following functions:

  • Support multi-level log messages
  • Support synchronous logs and asynchronous logs
  • Support reliable writing of logs to the console, files and rolling files
  • Support multi-threaded programs to write logs concurrently
  • Support the expansion of different log landing destinations

Core technology stack: class hierarchy design (inheritance and polymorphism), C++11 (multi-threading, right value references, etc.), double buffer, producer consumer model, multi-threading, design pattern (singleton, factory proxy, builder, etc.), GTest

Warning

This is a component-based project, not a business-based project, and it will eventually be used by others.

How to use

Performance Testing

Test environment:

  • Virtual Machine: Parallels Desktop, Ubuntu22.04 VirtualHost Memory 2G CPU Dual Core
  • Host: Macbook Air M2 Memory 16G

For how to use the bench code, see bench/bench.cc.

Test method: Each configuration was tested 10 times and the average result was taken. The results are shown below.

MODE Thead Number Message Size (KB) Message per second (M/s) Output Size per second (MB/s)
LOGGER_SYNC 1 976562(100 items) 1.60668 153.224
LOGGER_SYNC 10 976562 1.80325 171.971
LOGGER_ASYNC 1 976562 1.30354 124.314
LOGGER_ASYNC 10 976562 3.15184 300.582

Tip

The test results also show that in multi-threaded mode, the asynchronous working mode greatly improves performance.

Technical supplement

To complete this project, I used a document to supplement the detailed explanation of indeterminate parameter functions and six design patterns as a prerequisite technical supplement for this project.

Specific implementation of the project

The specific structure of the project is shown below.

For detailed implementation, see the following documents:

Some ideas

  • Encapsulate into a library
  • Understand how to encapsulate into interfaces of other languages, such as Python and C#, and try it. See if you can call the library in Python/C# to use this log system.

About

C++ version of synchronous & asynchronous logging system based on multiple design patterns

Resources

License

Stars

Watchers

Forks