Skip to content

sirz1rael/yetanotherlogger

Repository files navigation

Yet Another Logger

A lightweight, thread-safe, header-only C++17 logging library with Sink architecture, source location tracking, File Rotation, and Sanitizer Support.

Key Features

  • Header-only: Zero external dependencies (only standard C++17).
  • Sink Architecture: Easily log to console, files, or custom destinations.
  • File Rotation: Limit file size and number of log files automatically.
  • Thread-safe: Mutex-protected logging for multi-threaded applications.
  • Source Location: Captures file name, line number, and function name.
  • Quality Ensured: Built-in support for ASAN and Valgrind checks.

Technical Features & Debugging

AddressSanitizer (ASAN)

The library supports ASAN in Debug builds to catch memory errors early. To build with ASAN:

cmake .. -DCMAKE_BUILD_TYPE=Debug -DYAL_USE_ASAN=ON

Valgrind

A dedicated target is available to run memory leak checks using Valgrind:

cmake --build . --target valgrind-check

File Logging & Configuration

Rotating File Sink (Limits)

// Parameters: filename, max_file_size_bytes, max_files_to_keep
auto rotating = std::make_shared<Logger::RotatingFileSink>(
    "logs/app.log", 
    10 * 1024 * 1024, // 10 MB
    5                 // Keep 5 old log files
);
Logger::Logger::instance().add_sink(rotating);

Integration

Via CMake FetchContent

By default, examples and tests are not built when included as a subproject.

include(FetchContent)
FetchContent_Declare(
    yetanotherlogger
    GIT_REPOSITORY https://github.com/sirz1rael/yetanotherlogger.git
    GIT_TAG master
)
FetchContent_MakeAvailable(yetanotherlogger)

target_link_libraries(your_target PRIVATE yetanotherlogger::logger)

Available Options:

  • YAL_BUILD_EXAMPLES: Build example programs (Default: OFF as subproject)
  • YAL_BUILD_TESTS: Build unit tests (Default: OFF as subproject)
  • YAL_USE_ASAN: Enable AddressSanitizer (Default: OFF as subproject)

To enable an option from your main project:

set(YAL_BUILD_EXAMPLES ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(yetanotherlogger)

Testing

mkdir build && cd build
cmake .. -DYAL_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
make
ctest
# Run memory check
make valgrind-check

License

MIT License.

About

Header-only logger which can log into stringstream and filestream!

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors