a modern c++ header-only logging library
- beautiful aligned output with automatic color detection
- structured logging with key-value fields
- immutable scoped loggers for hierarchical context
- thread-safe by design
- zero dependencies, single header
- c++17 compatible
#include <redlog.hpp>
int main() {
auto log = redlog::get_logger("app");
log.info("hello world");
log.info("user login",
redlog::field("username", "alice"),
redlog::field("success", true));
auto db_log = log.with_name("database");
db_log.error("connection failed", redlog::field("host", "localhost"));
}cmake -B build
cmake --build build --parallelauto log = redlog::get_logger("myapp");
log.critical("system failure");
log.error("something went wrong");
log.warn("potential issue");
log.info("general information");
log.debug("debugging details");log.crt("critical"); // same as critical()
log.err("error"); // same as error()
log.inf("info"); // same as info()
log.dbg("debug"); // same as debug()log.info("user action",
redlog::field("user_id", 12345),
redlog::field("action", "login"),
redlog::field("ip", "192.168.1.100"));auto request_log = log.with_field("request_id", 12345)
.with_field("method", "POST");
auto handler_log = request_log.with_name("handler");
handler_log.info("processing request");log.info_f("user %s logged in from %s", username, ip_address);
log.error_f("failed to connect to %s:%s", host, port);// set minimum log level
redlog::set_level(redlog::level::debug);
// use plain theme (no colors)
redlog::set_theme(redlog::themes::plain);add redlog as a subdirectory to your cmake project:
add_subdirectory(redlog)
target_link_libraries(your_target PRIVATE redlog::redlog)copy include/redlog.hpp to your project and include it directly:
#include "redlog.hpp"
// ready to use - no linking requiredredlog is header-only with zero dependencies. simply:
- copy the header file or add as git submodule
- include in your source files
- compile with c++17 or later
cmake -B build -DREDLOG_BUILD_TESTS=ON
cmake --build build --parallel
./build/tests/redlog_tests