From f36b544b11219803fce02fe36f0a7eb20422a08b Mon Sep 17 00:00:00 2001 From: Ivan-lis Date: Thu, 19 Dec 2024 17:16:29 +0000 Subject: [PATCH] Fixed spdlog loglevel initialization --- CMakeLists.txt | 3 +++ tests/main.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b1728c7..3ed51f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ set(BOOST_INCLUDE_LIBRARIES "pfr;asio;serialization") option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON) option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF) option(BUILD_EXECUTABLE ON) +option(LOG_LEVEL 0 "Available log levels: 0=TRACE, 1=DEBUG,2= INFO,3= WARN, 4=ERROR, 5=CRITICAL, 6=OFF") # Compile program with highest available log levle to trace everything set(UTEMPL_URL "https://sha512sum.xyz/git/sha512sum/utempl" CACHE STRING "utempl repository URL") @@ -259,6 +260,7 @@ if(ENABLE_TESTS) target_sources(larra_xmpp_tests PUBLIC ${SOURCES}) target_link_libraries(larra_xmpp_tests GTest::gtest_main larra_xmpp) + target_compile_definitions(larra_xmpp_tests PRIVATE SPDLOG_ACTIVE_LEVEL=0) # SPDLOG_LEVEL_TRACE=0. Check LOG_LEVEL variable and spdlog documentation for more details set_property(TARGET larra_xmpp_tests PROPERTY CXX_STANDARD 23) include(GoogleTest) gtest_discover_tests(larra_xmpp_tests) @@ -270,6 +272,7 @@ if(ENABLE_EXAMPLES) get_filename_component(EXAMPLE_NAME ${EXAMPLE_SRC} NAME_WE) add_executable(${EXAMPLE_NAME} ${EXAMPLE_SRC}) target_link_libraries(${EXAMPLE_NAME} larra_xmpp) + target_compile_definitions(${EXAMPLE_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=${LOG_LEVEL}) set_property(TARGET ${EXAMPLE_NAME} PROPERTY CXX_STANDARD 23) set_target_properties(${EXAMPLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples/output") diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..538b54b --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,21 @@ +#include +#include + +#include +#include + +class PreconfigureEnvironment : public ::testing::Environment { + public: + void SetUp() override { + spdlog::set_level(spdlog::level::trace); + std::println("\nPreconfigureEnvironment setup:\n\tCompiled max availabel log level: {}\n\tCurrently set log level: {}", + SPDLOG_ACTIVE_LEVEL, + std::to_underlying(spdlog::get_level())); + } +}; + +auto main(int argc, char** argv) -> int { + ::testing::InitGoogleTest(&argc, argv); + ::testing::AddGlobalTestEnvironment(new PreconfigureEnvironment); // NOLINT GTest takes ownership + return RUN_ALL_TESTS(); +} \ No newline at end of file