From c15a14d2b23987573eb9cd15a9d7b3bae425a4b4 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Fri, 4 Sep 2020 07:01:58 +0100 Subject: [PATCH] Updated logging definitions to ensure it works using dynamic and static config --- README.md | 2 ++ single_include/kompute/Kompute.hpp | 8 +++--- src/Tensor.cpp | 2 ++ src/include/kompute/Core.hpp | 6 +++-- test/CMakeLists.txt | 4 +-- test/TestMain.cpp | 40 ++++++++++++------------------ 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 5d897c6bd..22c846be5 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,8 @@ SPDLOG is the preferred logging library, however by default Vulkan Kompute runs You can choose to build with or without SPDLOG by using the cmake flag `KOMPUTE_OPT_ENABLE_SPDLOG`. +Finally, remember that you will still need to set both the compile time log level with `SPDLOG_ACTIVE_LEVEL`, and the runtime log level with `spdlog::set_level(spdlog::level::debug);`. + ## Motivations diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index 3f2a6d1b5..6015009f5 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -3,11 +3,13 @@ #include // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import -#if DEBUG -#ifndef SPDLOG_ACTIVE_LEVEL +#if !defined(SPDLOG_ACTIVE_LEVEL) +#if RELEASE +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO +#else #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG -#endif #endif +#endif #ifndef KOMPUTE_LOG_OVERRIDE #if KOMPUTE_ENABLE_SPDLOG diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 167b9aaab..bca6c3500 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -18,8 +18,10 @@ Tensor::Tensor() Tensor::Tensor(std::vector data, TensorTypes tensorType) { +#if DEBUG SPDLOG_DEBUG( "Kompute Tensor constructor data: {}, and type: {}", data, tensorType); +#endif this->mData = data; this->mShape = { static_cast(data.size()) }; diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index e2aca74c7..5ac648ef0 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -3,11 +3,13 @@ #include // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import +#if !defined(SPDLOG_ACTIVE_LEVEL) #if DEBUG -#ifndef SPDLOG_ACTIVE_LEVEL #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG -#endif +#else +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO #endif +#endif #ifndef KOMPUTE_LOG_OVERRIDE #if KOMPUTE_ENABLE_SPDLOG diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 923c04fb5..904e7b4f2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,8 +15,8 @@ target_include_directories( ) target_link_libraries(test_kompute PRIVATE - GTest::gtest - GTest::gtest_main) + GTest::gtest + GTest::gmock) target_link_libraries(test_kompute PRIVATE kompute) diff --git a/test/TestMain.cpp b/test/TestMain.cpp index a9ecc279f..dbc580759 100644 --- a/test/TestMain.cpp +++ b/test/TestMain.cpp @@ -1,24 +1,16 @@ -//#define CATCH_CONFIG_RUNNER -// -//// clang-format: SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import -//#if DEBUG -//#ifndef SPDLOG_ACTIVE_LEVEL -//#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG -//#endif -//#endif -// -////#include -////// clang-format: ranges.h must come after spdlog.h -////#include -// -//#include "catch2/catch.hpp" -// -//int main( int argc, char* argv[] ) { -// -// int result = Catch::Session().run( argc, argv ); -// -// // global clean-up... -// -// return result; -//} -// + +#include + +#include + +int main(int argc, char *argv[]) { + testing::InitGoogleTest(&argc, argv); + testing::InitGoogleMock(&argc, argv); + +#if KOMPUTE_ENABLE_SPDLOG + spdlog::set_level(static_cast(SPDLOG_ACTIVE_LEVEL)); + spdlog::error("default active level {}", SPDLOG_ACTIVE_LEVEL); +#endif + + return RUN_ALL_TESTS(); +}