From fdad10c592734f35bff3354f4abcb3cf42fa2636 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 22 Jul 2025 16:58:05 -0500 Subject: [PATCH] added logging --- .../librepertory/include/comm/curl/curl_comm.hpp | 2 +- .../include/comm/curl/requests/http_delete.hpp | 10 ++++++---- .../include/comm/curl/requests/http_get.hpp | 8 +++++--- .../include/comm/curl/requests/http_head.hpp | 8 ++++---- .../include/comm/curl/requests/http_post.hpp | 10 ++-------- .../include/comm/curl/requests/http_put_file.hpp | 11 ++--------- .../include/comm/curl/requests/http_request_base.hpp | 2 ++ .../librepertory/include/events/types/curl_error.hpp | 11 ++++++++--- 8 files changed, 30 insertions(+), 32 deletions(-) diff --git a/repertory/librepertory/include/comm/curl/curl_comm.hpp b/repertory/librepertory/include/comm/curl/curl_comm.hpp index cba04458..707c5c38 100644 --- a/repertory/librepertory/include/comm/curl/curl_comm.hpp +++ b/repertory/librepertory/include/comm/curl/curl_comm.hpp @@ -224,7 +224,7 @@ public: if (curl_code != CURLE_OK) { event_system::instance().raise(curl_code, function_name, - url); + request.get_type(), url); return false; } diff --git a/repertory/librepertory/include/comm/curl/requests/http_delete.hpp b/repertory/librepertory/include/comm/curl/requests/http_delete.hpp index 41d6a94c..e8be7ce3 100644 --- a/repertory/librepertory/include/comm/curl/requests/http_delete.hpp +++ b/repertory/librepertory/include/comm/curl/requests/http_delete.hpp @@ -26,11 +26,13 @@ namespace repertory::curl::requests { struct http_delete final : http_request_base { - ~http_delete() override = default; + [[nodiscard]] auto get_type() const -> std::string override { + return "delete"; + } - [[nodiscard]] auto - set_method(CURL *curl, - stop_type & /* stop_requested */) const -> bool override { + [[nodiscard]] auto set_method(CURL *curl, + stop_type & /* stop_requested */) const + -> bool override { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); return true; } diff --git a/repertory/librepertory/include/comm/curl/requests/http_get.hpp b/repertory/librepertory/include/comm/curl/requests/http_get.hpp index e1f02326..92c3b55b 100644 --- a/repertory/librepertory/include/comm/curl/requests/http_get.hpp +++ b/repertory/librepertory/include/comm/curl/requests/http_get.hpp @@ -33,9 +33,11 @@ struct http_get final : http_request_base { auto operator=(http_get &&) -> http_get & = default; ~http_get() override = default; - [[nodiscard]] auto - set_method(CURL *curl, - stop_type & /*stop_requested*/) const -> bool override { + [[nodiscard]] auto get_type() const -> std::string override { return "get"; } + + [[nodiscard]] auto set_method(CURL *curl, + stop_type & /*stop_requested*/) const + -> bool override { curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); return true; } diff --git a/repertory/librepertory/include/comm/curl/requests/http_head.hpp b/repertory/librepertory/include/comm/curl/requests/http_head.hpp index 341bed8f..26b37347 100644 --- a/repertory/librepertory/include/comm/curl/requests/http_head.hpp +++ b/repertory/librepertory/include/comm/curl/requests/http_head.hpp @@ -26,11 +26,11 @@ namespace repertory::curl::requests { struct http_head final : http_request_base { - ~http_head() override = default; + [[nodiscard]] auto get_type() const -> std::string override { return "head"; } - [[nodiscard]] auto - set_method(CURL *curl, - stop_type & /* stop_requested */) const -> bool override { + [[nodiscard]] auto set_method(CURL *curl, + stop_type & /* stop_requested */) const + -> bool override { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD"); curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); return true; diff --git a/repertory/librepertory/include/comm/curl/requests/http_post.hpp b/repertory/librepertory/include/comm/curl/requests/http_post.hpp index c5425e12..d465d0ef 100644 --- a/repertory/librepertory/include/comm/curl/requests/http_post.hpp +++ b/repertory/librepertory/include/comm/curl/requests/http_post.hpp @@ -26,16 +26,10 @@ namespace repertory::curl::requests { struct http_post final : http_request_base { - http_post() = default; - http_post(const http_post &) = default; - http_post(http_post &&) = default; - auto operator=(const http_post &) -> http_post & = default; - auto operator=(http_post &&) -> http_post & = default; - - ~http_post() override = default; - std::optional json; + [[nodiscard]] auto get_type() const -> std::string override { return "post"; } + [[nodiscard]] auto set_method(CURL *curl, stop_type & /*stop_requested*/) const -> bool override; diff --git a/repertory/librepertory/include/comm/curl/requests/http_put_file.hpp b/repertory/librepertory/include/comm/curl/requests/http_put_file.hpp index 8841adc4..3310210b 100644 --- a/repertory/librepertory/include/comm/curl/requests/http_put_file.hpp +++ b/repertory/librepertory/include/comm/curl/requests/http_put_file.hpp @@ -27,18 +27,11 @@ namespace repertory::curl::requests { struct http_put_file final : http_request_base { - http_put_file() = default; - http_put_file(const http_put_file &) = default; - http_put_file(http_put_file &&) = default; - - auto operator=(const http_put_file &) -> http_put_file & = default; - auto operator=(http_put_file &&) -> http_put_file & = default; - - ~http_put_file() override = default; - std::shared_ptr reader; std::string source_path; + [[nodiscard]] auto get_type() const -> std::string override { return "put"; } + [[nodiscard]] auto set_method(CURL *curl, stop_type &stop_requested) const -> bool override; diff --git a/repertory/librepertory/include/comm/curl/requests/http_request_base.hpp b/repertory/librepertory/include/comm/curl/requests/http_request_base.hpp index a99d88da..0246dbc4 100644 --- a/repertory/librepertory/include/comm/curl/requests/http_request_base.hpp +++ b/repertory/librepertory/include/comm/curl/requests/http_request_base.hpp @@ -61,6 +61,8 @@ struct http_request_base { [[nodiscard]] virtual auto get_path() const -> std::string { return path; } + [[nodiscard]] virtual auto get_type() const -> std::string = 0; + [[nodiscard]] virtual auto set_method(CURL *curl, stop_type &stop_requested) const -> bool = 0; diff --git a/repertory/librepertory/include/events/types/curl_error.hpp b/repertory/librepertory/include/events/types/curl_error.hpp index cb3bcee6..a255fd59 100644 --- a/repertory/librepertory/include/events/types/curl_error.hpp +++ b/repertory/librepertory/include/events/types/curl_error.hpp @@ -28,9 +28,11 @@ namespace repertory { struct curl_error final : public i_event { curl_error() = default; - curl_error(CURLcode code_, std::string_view function_name_, std::string url_) + curl_error(CURLcode code_, std::string_view function_name_, std::string type_, + std::string url_) : code(code_), function_name(std::string{function_name_}), + type(std::move(type_)), url(std::move(url_)) {} static constexpr event_level level{event_level::error}; @@ -38,6 +40,7 @@ struct curl_error final : public i_event { CURLcode code{}; std::string function_name; + std::string type; std::string url; [[nodiscard]] auto get_event_level() const -> event_level override { @@ -49,8 +52,8 @@ struct curl_error final : public i_event { } [[nodiscard]] auto get_single_line() const -> std::string override { - return fmt::format("{}|func|{}|url|{}|code|{}", name, function_name, url, - static_cast(code)); + return fmt::format("{}|func|{}|type|{}|url|{}|code|{}", name, function_name, + type, url, static_cast(code)); } }; } // namespace repertory @@ -60,12 +63,14 @@ template <> struct adl_serializer { static void to_json(json &data, const repertory::curl_error &value) { data["code"] = value.code; data["function_name"] = value.function_name; + data["type"] = value.type; data["url"] = value.url; } static void from_json(const json &data, repertory::curl_error &value) { data.at("code").get_to(value.code); data.at("function_name").get_to(value.function_name); + data.at("type").get_to(value.type); data.at("url").get_to(value.url); } };