From de0e690ffc1961e012e0da8b07e841b1235e587f Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Mon, 13 Apr 2026 14:50:49 +0200 Subject: [PATCH] Fix logging for tests and examples Remove the use of the LCM_LOG_DEFAULT_ENABLED compile definition. LCM_LOG has to be enable always at runtime. Enable LCM_LOG at runtime for the tests and the example. This solves #24. Signed-off-by: Eduardo Gonzalez --- examples/CMakeLists.txt | 2 -- examples/connmanctl.cpp | 1 + include/amarula/log.hpp | 4 ---- tests/CMakeLists.txt | 5 ++--- tests/logging_init.cpp | 9 +++++++++ 5 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 tests/logging_init.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 5c49e5c..c0a2070 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,3 @@ -add_compile_definitions(LCM_LOG_DEFAULT_ENABLED=1) - if(BUILD_CONNMAN) add_executable(connmanctl_dbus connmanctl.cpp) target_link_libraries(connmanctl_dbus PRIVATE GConnmanDbus) diff --git a/examples/connmanctl.cpp b/examples/connmanctl.cpp index 27c2c5d..74b1965 100644 --- a/examples/connmanctl.cpp +++ b/examples/connmanctl.cpp @@ -18,6 +18,7 @@ auto main() -> int { std::mutex cin_mutex; std::condition_variable cin_cv; bool connecting = false; + Amarula::Log::enable(true); Connman connman; const auto manager = connman.manager(); manager->onRequestInputPassphrase([&](const auto& service) -> auto { diff --git a/include/amarula/log.hpp b/include/amarula/log.hpp index 9069a41..01a7cb4 100644 --- a/include/amarula/log.hpp +++ b/include/amarula/log.hpp @@ -24,11 +24,7 @@ class Log { private: static auto state() -> std::atomic& { -#ifdef LCM_LOG_DEFAULT_ENABLED - static std::atomic flag{true}; -#else static std::atomic flag{false}; -#endif return flag; } }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 432499a..4278f0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,3 @@ -add_compile_definitions(LCM_LOG_DEFAULT_ENABLED=1) - include(FetchContent) FetchContent_Declare( googletest @@ -22,7 +20,8 @@ install( if(BUILD_CONNMAN) foreach(connman_test gconnman_clock_test gconnman_tech_test gconnman_serv_test) - add_executable(${connman_test} ${connman_test}.cpp qt_thread_bundle.hpp) + add_executable(${connman_test} ${connman_test}.cpp qt_thread_bundle.hpp + logging_init.cpp) target_link_libraries(${connman_test} PRIVATE GConnmanDbus gtest_main) target_include_directories(${connman_test} diff --git a/tests/logging_init.cpp b/tests/logging_init.cpp new file mode 100644 index 0000000..db28bd3 --- /dev/null +++ b/tests/logging_init.cpp @@ -0,0 +1,9 @@ +#include + +namespace { +struct EnableLogging { + EnableLogging() { Amarula::Log::enable(true); } +}; + +[[maybe_unused]] EnableLogging enable_logging; +} // namespace