Comparison of C++ logging libraries

2025年5月24日

Requirements:

fine-grained log level control. In general, output WARNING level, but for some classes output INFO level.

Optional:

Escape newline characters.

Google glog

glog is no longer maintained. ng-log is a successor. Neither documentation is super comprehensive.

glog and ng-log do not natively support Visual Studio build system. If you don’t have gflags, create a build tree with
cmake -S . -B build -G "Visual Studio 17 2022" -A Win32 -DWITH_GFLAGS=OFF.

Nevertheless, I still failed to see INFO level logs.

spdlog

spdlog uses the fmt library for formatting. I am quite happy with C++20’s std::format. I don’t want to learn new formatting syntax.

choll xtr

xtr uses the fmt library for formatting.

ChristianPanov lwlog

lwlog has quite a number of obvious but minor bugs. What’s more, its support of C++ std::format is superficial. The execution path to std::format has never actually worked.[1]

SergiusTheBest plog

plog is easy to use. It requires no compilation. It uses the style of std::cout to write logs, and writes whatever std::format returns. Therefore I don’t have to learn new formatting syntax.

plog has a number of formatters. I mainly concern TxtFormatter. It does not support formatting patterns, and I must write a custom formatter if I want to change log formats. Luckly copying and modifying TxtFormatter is easy as pie.

You can create multiple logger instances with plog, each having a different instance id. Then you can write a custom formatter that converts the integer id to something meaningful.

I eventually choose plog because of its simplicity and ease to use.

References

  1. gqqnbig. Can't call std::format. . 2025-05-24 [].