A lightweight, thread-friendly logging library for C++ with stream-style macros, file logging, and configurable log levels.
git clone git@github.com:jayasankar-jp/logger-cpp.gitgit clone git@github.com:jayasankar-jp/logger-cpp.git
cd logger-cppmkdir build
cd build
cmake ..
makesudo make install| Type | Location |
|---|---|
| Library | /usr/local/lib/libLogger.a |
| Headers | /usr/local/include/ |
| CMake Config | /usr/local/lib/cmake/Logger/ |
#include <Logger.h>
int main() {
std::shared_ptr<Logger> log = Logger::getInstance();
log->setAppName("MQTT_APP");
log->setLogPath("./LOGS");
log->setLogLevel(31);
log_debug << "Test debug print";
log_error << "ERROR msg";
log_verbos << "verbose message";
log_info << "My info";
return 0;
}cmake_minimum_required(VERSION 3.15)
project(MyApp)
find_package(Logger REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app Logger::Logger)mkdir build
cd build
cmake ..
make
./applist(APPEND CMAKE_PREFIX_PATH "/your/install/path")
find_package(Logger REQUIRED)add_subdirectory(logger-cpp)
add_executable(app main.cpp)
target_link_libraries(app Logger)| Macro | Description |
|---|---|
log_error |
Error messages |
log_debug |
Debug messages |
log_info |
Informational |
log_verbose |
Verbose logging |
Logs are stored in:
./LOGS/<APP_NAME>_<DATE>.log
LOGS/MQTT_APP_15-04-2026.log
Hereโs your updated Configuration section with the new options added, clean and consistent:
log->setAppName("MY_APP");log->setLogPath("./LOGS");log->setLogLevel(31);log->setMaxFileGenPeriodMin(10);Description:
- Creates a new log file after the specified time interval.
- Example:
10โ new file every 10 minutes.
log->setMaxFileSizeMB(5);Description:
- Limits how large a log file can grow.
- When exceeded, a new log file is created.
- Example:
5โ max 5 MB per file.
-
Log rotation happens when either condition is met:
- โฑ๏ธ Time limit (
setMaxFileGenPeriodMin) - ๐ฆ Size limit (
setMaxFileSizeMB)
- โฑ๏ธ Time limit (
- Singleton Logger instance
- Stream-style logging (
<<) - File-based logging
- Configurable log levels
- Easy integration with CMake
-
Include header as:
#include <Logger.h>
-
Ensure log directory exists or is creatable
-
Static library (
.a) by default
- Async logging
- Log rotation
- Shared library (.so)
- Colored console output
Jayasankar JP
Pull requests are welcome!
If you encounter any issues, bugs, or have feature requests, please open an issue on GitHub.