Skip to content

jayasankar-jp/logger-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“˜ Logger C++ Library

A lightweight, thread-friendly logging library for C++ with stream-style macros, file logging, and configurable log levels.


๐Ÿ”— Repository

git clone git@github.com:jayasankar-jp/logger-cpp.git

โš™๏ธ Installation

โœ… 1. Clone the repository

git clone git@github.com:jayasankar-jp/logger-cpp.git
cd logger-cpp

โœ… 2. Build

mkdir build
cd build
cmake ..
make

โœ… 3. Install (System-wide)

sudo make install

๐Ÿ“ฆ Installed files

Type Location
Library /usr/local/lib/libLogger.a
Headers /usr/local/include/
CMake Config /usr/local/lib/cmake/Logger/

๐Ÿš€ Usage

โœ… Example Code

#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;
}

๐Ÿงฉ Using in Another Project (CMake)

โœ… Method 1: Installed Library (Recommended)

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(MyApp)

find_package(Logger REQUIRED)

add_executable(app main.cpp)

target_link_libraries(app Logger::Logger)

โ–ถ๏ธ Build

mkdir build
cd build
cmake ..
make
./app

โœ… Method 2: If Installed in Custom Path

list(APPEND CMAKE_PREFIX_PATH "/your/install/path")

find_package(Logger REQUIRED)

โœ… Method 3: Use Without Installing

add_subdirectory(logger-cpp)

add_executable(app main.cpp)

target_link_libraries(app Logger)

๐Ÿ“Š Log Levels

Macro Description
log_error Error messages
log_debug Debug messages
log_info Informational
log_verbose Verbose logging

๐Ÿ“ Log Output

Logs are stored in:

./LOGS/<APP_NAME>_<DATE>.log

Example:

LOGS/MQTT_APP_15-04-2026.log

Hereโ€™s your updated Configuration section with the new options added, clean and consistent:


โš™๏ธ Configuration

๐Ÿ”น Set Application Name

log->setAppName("MY_APP");

๐Ÿ”น Set Log Path

log->setLogPath("./LOGS");

๐Ÿ”น Set Log Level

log->setLogLevel(31);

๐Ÿ”น Set Max File Generation Period (Minutes)

log->setMaxFileGenPeriodMin(10);

Description:

  • Creates a new log file after the specified time interval.
  • Example: 10 โ†’ new file every 10 minutes.

๐Ÿ”น Set Max File Size (MB)

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.

๐Ÿ“Œ Notes

  • Log rotation happens when either condition is met:

    • โฑ๏ธ Time limit (setMaxFileGenPeriodMin)
    • ๐Ÿ“ฆ Size limit (setMaxFileSizeMB)

๐Ÿง  Features

  • Singleton Logger instance
  • Stream-style logging (<<)
  • File-based logging
  • Configurable log levels
  • Easy integration with CMake

โš ๏ธ Notes

  • Include header as:

    #include <Logger.h>
  • Ensure log directory exists or is creatable

  • Static library (.a) by default


๐Ÿ”ฎ Future Improvements

  • Async logging
  • Log rotation
  • Shared library (.so)
  • Colored console output

๐Ÿ‘จโ€๐Ÿ’ป Author

Jayasankar JP


โญ Contributing

Pull requests are welcome!

If you encounter any issues, bugs, or have feature requests, please open an issue on GitHub.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors