CX is a set of C++ header-only utilities for simple applications in C++23. Right now, it provides a customizable stream-based logging implementation.
- Stream based Logger : Write to any std::ostream& object
- Multiple Log Levels : Trace, Debug, Info, Warn, Error
- Configurable Verbosity & Prefix : Three verbosity levels for logger messages, and ability to add a prefix
- Formatted Log Messages : Supports
std::format/std::printstyle logging, so you don't have to use any of those to build the message string.
With file stream:
auto file = std::ofstream{"file.txt"};
auto logger = cx::Logger{file};With a string stream:
auto buffer = std::ostringstream{};
auto logger = cx::Logger{buffer};#include <cx/logger.hpp>
#include <iostream> // for std::cout
int main() {
auto logger = cx::Logger{std::cout}; // log to std::cout
logger.minimumLevel = cx::LogLevel::Trace;
logger.verbosity = cx::LogMsgVerbosity::Maximum;
logger.prefix = "Example";
std::string user = "alice";
std::string ip = "192.168.1.55";
std::vector<int> values{1, 2, 3, 4};
logger.info("User {} connected from {}", user, ip);
logger.debug("Vector value contains {} elements", values.size());
logger.trace("value[0] = {}", values[0]);
logger.trace("value = {}", values);
}- Sample Output
[Example] | [INFO] | [2025-09-11 05:16:17.827337558] | getting_started.cpp(13:17) | [int main()] | User alice connected from 192.168.1.55
[Example] | [DEBUG] | [2025-09-11 05:16:17.827402093] | getting_started.cpp(14:18) | [int main()] | Vector value contains 4 elements
[Example] | [TRACE] | [2025-09-11 05:16:17.827416903] | getting_started.cpp(15:18) | [int main()] | value[0] = 1
[Example] | [TRACE] | [2025-09-11 05:16:17.827428743] | getting_started.cpp(16:18) | [int main()] | value = [1, 2, 3, 4][DEBUG] | [2025-10-11 07:07:19.706234057] | Message[DEBUG] | [2025-10-11 07:07:19.706234057] | main.cpp(12:30) | Message[DEBUG] | [2025-10-11 07:07:19.706234057] | main.cpp(12:30) | [int main()] | Message