Questions to be answered before integrating logging library into your C++ project.

Questions to be answered before logging integration into your C++ project

  1. What logging library is best fit for my C++ Linux project?
    There are few options of C++ logging libraries. Which one to use depends on how big and complex your project gonna become. But besides that the minimal set of features it should has is:
    - multithreading/async writing to log files,
    - configuration from config file and trace filtering from config,
    - log rotation support,
    - good documentation and library support itself.
  2. There are around 10 possible options for C++: Pantheios, Glog, log4cpp, P7, G3log, Spdlog, Easylogging, Boost.Log.
    So, what library to pick? If your project is kind of small, hobby projects pick Glog or Log4cpp.
    Otherwise, you should be looking for well optimised and customasible solution which could be P7 or boost::log.
    Interesting fact: among all libs, only Glog has crash handling support (SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, SIGTERM). Which is really good for C++ aplications.
  3. How are you gonna read your logs?
    This may affect logs format and where you keep your logs. Here is an article where you can read about 4 different tools which let you read logs in Unix/Linux systems: Best Linux Log Monitoring and Management Tools.
    If you picked P7 library, it will be useful to take a look at theirs own tools: Baical.
  4. What should be logs message format?
    Kind of standart format is: [Time][Log level] — [File]:[Line] [Function] — [Text]. If app is multithreaded/modular, add [Module][Thread] options as well. Set names to threads, don’t be lasy, it will be much more readable.
    Above you can see an example how logs could be visualised if you set up it right.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Iryna Mykytyn

Iryna Mykytyn


Computer programmer specialised in C++ and the Linux OS . Passionate about coding, technologies and learning new tools for optimisation and performance analysis