diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ce275ccb..22329b4e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,7 @@ find_package(Threads) add_library(catch INTERFACE) target_include_directories(catch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -file(GLOB catch_tests LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +file(GLOB catch_tests LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.h *.hpp) add_executable(catch_tests ${catch_tests}) target_link_libraries(catch_tests spdlog ${CMAKE_THREAD_LIBS_INIT}) diff --git a/tests/async_logger.cpp b/tests/async_logger.cpp new file mode 100644 index 00000000..bcfb1ca6 --- /dev/null +++ b/tests/async_logger.cpp @@ -0,0 +1,38 @@ + +#include + +#include "includes.h" +#include "../include/spdlog/common.h" +#include "../include/spdlog/tweakme.h" + + +TEST_CASE("async_logging_overflow ", "[async_logging]") +{ + std::string filename = "logs/async_log_overflow.txt"; + auto sink = std::make_shared(filename, true); + auto logger = std::make_shared( + "overflow_logger", + sink, + 2, // queue size + spdlog::async_overflow_policy::discard_log_msg + ); + for (int i = 0; i < 8; i++) { + logger->info("Message #{}", i); + } + logger->flush(); + logger.reset(); + std::string the_log = file_contents(filename); +#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG) + std::cout << the_log << std::endl; + REQUIRE(the_log.find("Dropped 6 messages") != std::string::npos); +#endif +} + + + + + + + + +