Fixed spdlog loglevel initialization

This commit is contained in:
Ivan-lis 2024-12-19 17:16:29 +00:00
parent 7f5c9cfd49
commit d06d02efc0
2 changed files with 24 additions and 0 deletions

View file

@ -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")

21
tests/main.cpp Normal file
View file

@ -0,0 +1,21 @@
#include <gtest/gtest.h>
#include <spdlog/spdlog.h>
#include <print>
#include <utility>
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();
}