drop one header into your project and get colored, leveled, formatted logging.
#include "cpplog/log.hpp"
cpplog::info("server started on port {}", 8080);
cpplog::warn("memory at {}%", 87);
cpplog::error("connection failed: {}", "timeout");
cpplog::debug("loaded {} entries", count);output in terminal (color-coded by level):
[INFO ] 14:02:11 server started on port 8080
[WARN ] 14:02:11 memory at 87%
[ERROR] 14:02:11 connection failed: timeout
[DEBUG] 14:02:11 loaded 42 entries
copy include/cpplog/log.hpp into your project.
or with CMake FetchContent:
include(FetchContent)
FetchContent_Declare(cpplog
GIT_REPOSITORY https://github.com/ligumas/cpplog.git
GIT_TAG main
)
FetchContent_MakeAvailable(cpplog)
target_link_libraries(your_target cpplog)#include "cpplog/log.hpp"
cpplog::debug("x = {}", x);
cpplog::info("ready");
cpplog::warn("high load: {}%", load);
cpplog::error("failed: {}", msg);
cpplog::set_level(cpplog::Level::WARN); // filter below WARN
cpplog::set_color(false); // disable ANSI (e.g. piped output)
cpplog::set_time(false); // drop timestamp (log collector adds its own)
cpplog::set_file("app.log"); // also write to fileuse the CPPLOG_* macros when you want file and line in the output:
CPPLOG_INFO("loading {} samples", n);
CPPLOG_WARN("slow response: {}ms", ms);
CPPLOG_ERROR("disk full");[INFO ] 14:02:11 main.cpp:12 loading 500 samples
[WARN ] 14:02:11 server.cpp:87 slow response: 340ms
[ERROR] 14:02:11 disk.cpp:203 disk full
set_time(false) still keeps file:line when using CPPLOG_* macros — you get location without the clock.
- single header, zero dependencies
- C++17, Linux/Windows/macOS
{}placeholder formatting- log levels: DEBUG INFO WARN ERROR
- colored terminal output (ANSI)
- optional file output
- optional timestamp (
set_time(false)for structured log collectors) - thread-safe
CPPLOG_*macros for file:line source location
cmake -B build && cmake --build build
./build/testsLicense: MIT