From c631e5c4fea63df28ae01dac2483c3f91eaff2ea Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 24 Dec 2019 18:53:45 +0100 Subject: [PATCH] Add debug logging. --- man/mastorss.1.adoc | 14 +++++++++++++- src/CMakeLists.txt | 9 +++++++-- src/document.cpp | 6 +++++- src/main.cpp | 21 ++++++++++++++++++++- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/man/mastorss.1.adoc b/man/mastorss.1.adoc index 15c6d92..4d15d64 100644 --- a/man/mastorss.1.adoc +++ b/man/mastorss.1.adoc @@ -2,7 +2,7 @@ :doctype: manpage :Author: tastytea :Email: tastytea@tastytea.de -:Date: 2019-12-20 +:Date: 2019-12-24 :Revision: 0.0.0 :man source: mastorss :man manual: General Commands Manual @@ -71,6 +71,18 @@ Example: `http_proxy="http://localhost:3128/" mastorss` | 9 | Unknown error. |=========================================================== +== DEBUGGING + +Define the variable `MASTORSS_DEBUG` to enable debug output. + +.Debug mastorss while using the profile “example”. +================================================================================ +[source,shell] +-------------------------------------------------------------------------------- +MASTORSS_DEBUG=1 mastorss example +-------------------------------------------------------------------------------- +================================================================================ + == SEE ALSO *curl*(1), *crontab*(1), *crontab*(5) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dca891e..e1ac829 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ include(GNUInstallDirs) # The minimum versions should be in Debian oldstable, if possible. -find_package(Boost 1.62 REQUIRED COMPONENTS system filesystem) +find_package(Boost 1.62 REQUIRED COMPONENTS system filesystem log) find_package(jsoncpp 1.7 REQUIRED CONFIG) find_package(CURL 7.52 REQUIRED) find_package(Threads REQUIRED) @@ -18,7 +18,12 @@ include_directories("${PROJECT_BINARY_DIR}") file(GLOB sources *.cpp) add_executable(mastorss ${sources}) target_link_libraries(mastorss - mastodon-cpp::mastodon-cpp Boost::system Boost::filesystem restclient-cpp) + PRIVATE + jsoncpp restclient-cpp mastodon-cpp::mastodon-cpp + Boost::filesystem Boost::log) +if(BUILD_SHARED_LIBS) + target_compile_definitions(mastorss PRIVATE "BOOST_ALL_DYN_LINK=1") +endif() install(TARGETS mastorss DESTINATION "${CMAKE_INSTALL_BINDIR}") install(FILES watchwords.json diff --git a/src/document.cpp b/src/document.cpp index 0bf97e9..bd7531b 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -18,13 +18,15 @@ #include "exceptions.hpp" #include "version.hpp" +#include #include #include #include #include -using namespace mastorss; +namespace mastorss +{ using std::string; using std::move; @@ -54,6 +56,7 @@ void Document::download() case 200: { _raw_doc = response.body; + BOOST_LOG_TRIVIAL(debug) << "Downloaded feed: " << _uri; break; } case 301: @@ -73,3 +76,4 @@ void Document::download() } } } +} // namespace mastorss diff --git a/src/main.cpp b/src/main.cpp index 4e5c6d3..0f6d1de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,13 +3,21 @@ #include "exceptions.hpp" #include "version.hpp" +#include +#include +#include + +#include #include +#include #include #include using namespace mastorss; +using std::getenv; using std::cout; using std::cerr; +using std::runtime_error; using std::string_view; using std::vector; @@ -40,7 +48,7 @@ void print_version() void print_help(const string_view &command) { - cerr << "Usage: " << command << " [--version] \n"; + cerr << "Usage: " << command << " [--version|--help] \n"; } } // namespace mastorss @@ -48,6 +56,17 @@ int main(int argc, char *argv[]) { const vector args(argv, argv + argc); + if (getenv("MASTORSS_DEBUG") == nullptr) + { + boost::log::core::get()->set_filter + (boost::log::trivial::severity >= boost::log::trivial::info); + } + else + { + boost::log::core::get()->set_filter + (boost::log::trivial::severity >= boost::log::trivial::debug); + } + if (args.size() == 1) { print_help(args[0]);