From bb59c65848cbb8c0f4719a13e5891843064df7d2 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sun, 2 Oct 2016 02:37:35 +0300 Subject: [PATCH] Removed Boost.Log dependency. --- include/telebotxx/Logging.hpp | 12 ++++++++++++ src/BotApi.cpp | 13 ++++++++----- src/CMakeLists.txt | 13 ++++--------- src/Logging.cpp | 11 +++++++++++ tests/CMakeLists.txt | 2 +- tests/TestApi.cpp | 3 +++ 6 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 include/telebotxx/Logging.hpp create mode 100644 src/Logging.cpp diff --git a/include/telebotxx/Logging.hpp b/include/telebotxx/Logging.hpp new file mode 100644 index 0000000..2866077 --- /dev/null +++ b/include/telebotxx/Logging.hpp @@ -0,0 +1,12 @@ +#ifndef TELEBOTXX_LOGGING_HPP +#define TELEBOTXX_LOGGING_HPP + +namespace telebotxx +{ + extern bool debugMode; + + /// \brief Enable/disable debug output + void setDebugMode(bool enabled); +} + +#endif // TELEBOTXX_LOGGING_HPP diff --git a/src/BotApi.cpp b/src/BotApi.cpp index d573d31..61634ed 100644 --- a/src/BotApi.cpp +++ b/src/BotApi.cpp @@ -1,6 +1,8 @@ #include #include +#include +#include #include #include @@ -8,8 +10,6 @@ #include -#include - namespace telebotxx { const rapidjson::Value& parseResponse(const rapidjson::Document& doc) @@ -91,7 +91,8 @@ public: auto r = cpr::Get(cpr::Url{telegramMainUrl_ + "/getMe"}); auto& response = r.text; - BOOST_LOG_TRIVIAL(debug) << response; + if (debugMode) + std::cout << "Response: " << response << std::endl; using namespace rapidjson; Document doc; @@ -122,7 +123,8 @@ public: ); auto& response = r.text; - BOOST_LOG_TRIVIAL(debug) << response; + if (debugMode) + std::cout << "Response: " << response << std::endl; using namespace rapidjson; Document doc; @@ -142,7 +144,8 @@ public: ); auto& response = r.text; - BOOST_LOG_TRIVIAL(debug) << response; + if (debugMode) + std::cout << "Response: " << response << std::endl; using namespace rapidjson; Document doc; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd05c43..c9e1cea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,12 +2,6 @@ cmake_minimum_required(VERSION 2.8) message(STATUS "Configuring telebotxx") -find_package(Boost 1.54 REQUIRED log system) -include_directories(${Boost_INCLUDE_DIRS}) - -#find_package(CURLpp REQUIRED) -#include_directories(${CURLPP_INCLUDE_DIRS}) - # Add required gcc flags # For Windows we suppress all warnings because of Boost garbage :( if(NOT WIN32) @@ -19,11 +13,12 @@ endif(NOT WIN32) # Put compiled library to 'lib' directory set(LIBRARY_OUTPUT_PATH "../lib") - set(SOURCE_FILES BotApi.cpp + Logging.cpp User.cpp ) add_library(telebotxx SHARED ${SOURCE_FILES}) -target_link_libraries(telebotxx ${Boost_LIBRARIES} ${CPR_LIBRARIES}) -set_property(TARGET telebotxx APPEND PROPERTY COMPILE_DEFINITIONS BOOST_LOG_DYN_LINK) +target_link_libraries(telebotxx ${CPR_LIBRARIES}) + +message(STATUS "Configuring telebotxx - done") diff --git a/src/Logging.cpp b/src/Logging.cpp new file mode 100644 index 0000000..a075c30 --- /dev/null +++ b/src/Logging.cpp @@ -0,0 +1,11 @@ +#include + +namespace telebotxx +{ + bool debugMode = false; + + void setDebugMode(bool enabled) + { + debugMode = enabled; + } +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f2210fb..5c5eaf8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,4 +25,4 @@ target_link_libraries(telebotxx-test telebotxx stdc++ ${Boost_LIBRARIES}) add_custom_target(test COMMAND telebotxx-test WORKING_DIRECTORY ".." DEPENDS telebotxx-test) -message(STATUS "Configuring telebotxx-test done") +message(STATUS "Configuring telebotxx-test - done") diff --git a/tests/TestApi.cpp b/tests/TestApi.cpp index b62e34b..65d6175 100644 --- a/tests/TestApi.cpp +++ b/tests/TestApi.cpp @@ -1,6 +1,7 @@ #include "TestGlobal.hpp" #include +#include #include #include @@ -61,6 +62,8 @@ struct TestConfig throw std::invalid_argument("Config error: 'photo' must be unsigned int value."); else throw std::invalid_argument("Config error: 'photo' not set."); + + telebotxx::setDebugMode(true); } ~TestConfig()