How to log?

EDIT: Whatever I wrote here is nothing compared to what this guy did in here https://weekly-geekly.github.io/articles/313686/index.html. It is a must-read if you are interested in this topic.

I have recently faced a problem while developing large monolithic projects. The question is easy, What is the best way to log from different places of the project without inferring the normal execution of their tasks? It might not seem important but when some of these pieces of the projects are needed to run in real-time, injecting slow pieces of code might highly influence the performance of the system.

This is going to be a short post to collect different answers and solutions that I found on the internet of people asking the same question.

Namec++AsynchronousMultiple FilesLatencyOStools
Boost.LogyesALL
uberlogyesyes~240nsALL
NanoLogyesnoALL
g2logyesyesALL
g3logyesyesALL
spdlogyesyesnoALL
Baical p7yesyesALLViewer,
Remote
recklessyesyesALL

After all, NanoLog seemed to be the best option in terms of larger throughput and smaller blocking time. It is crazily insane how these guys from Stanford realize that they can boost the log system by taking advantage of the compilation time information available from the data types [3]. However, its interface is not very c++11/14/17 friendly, it is thought to have just one log file, which might not be good for some situations, and to take all the advantages it is necessary to modify the compilation pipeline of your project.

Alternatively, there are two interesting options p7 and reckless. Particularly, in the repository of the second one, there is a very deep benchmark of the tool which shows very good results.

Concerning p7 by Baical, it has the advantages of offering a network pipeline to not only log but send telemetry. Also, it provides for the other side tools to receive the telemetry data.

EDIT: There is also a good summary in https://github.com/fffaraz/awesome-cpp#logging

References

  1. https://www.boost.org/doc/libs/1_72_0/libs/log/doc/html/index.html
  2. https://stackoverflow.com/questions/2930258/asynchronous-thread-safe-logging-in-c
  3. https://www.usenix.org/system/files/conference/atc18/atc18-yang.pdf
  4. https://github.com/IMQS/uberlog
  5. https://www.scalyr.com/blog/getting-started-quickly-c++-logging
  6. https://www.codeproject.com/Articles/288827/g-log-An-efficient-asynchronous-logger-using-Cplus
  7. https://gamedev.stackexchange.com/questions/8691/logging-library-for-c-games