diff options
| author | Per Larsson <[email protected]> | 2021-09-07 10:26:10 +0200 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-09-07 10:26:10 +0200 |
| commit | 20b15d45bd9b34a3f9297c4be1525e25379e5602 (patch) | |
| tree | e7208bd37d364fb9ea413ee7c750a6c6f58e92f7 /zenserver/upstream/zen.cpp | |
| parent | Support for switching between storing derived data using the legacy DDC endpo... (diff) | |
| download | zen-20b15d45bd9b34a3f9297c4be1525e25379e5602.tar.xz zen-20b15d45bd9b34a3f9297c4be1525e25379e5602.zip | |
Added custom cpr::Response formatter and removed duplicate logging code.
Diffstat (limited to 'zenserver/upstream/zen.cpp')
| -rw-r--r-- | zenserver/upstream/zen.cpp | 47 |
1 files changed, 5 insertions, 42 deletions
diff --git a/zenserver/upstream/zen.cpp b/zenserver/upstream/zen.cpp index 3d4999e5d..7ed4eead0 100644 --- a/zenserver/upstream/zen.cpp +++ b/zenserver/upstream/zen.cpp @@ -8,6 +8,7 @@ #include <zencore/stream.h> #include "cache/structuredcachestore.h" +#include "diag/formatters.h" #include "diag/logging.h" // cpr //////////////////////////////////////////////////////////////////// @@ -323,44 +324,6 @@ namespace detail { cpr::Session Session; }; - static void LogResponse(spdlog::logger& Log, std::string_view Verb, const cpr::Response& Response) - { - using namespace std::literals; - - std::string_view ContentType = "unknown"sv; - if (auto It = Response.header.find("Content-Type"); It != Response.header.end()) - { - ContentType = It->second; - } - - const uint64_t Bytes = Verb == "GET"sv ? Response.downloaded_bytes : Response.uploaded_bytes; - - const bool IsBinary = - ContentType == "application/x-ue-cb"sv || ContentType == "application/x-ue-comp"sv || ContentType == "application/octet-stream"; - - if (IsBinary) - { - Log.debug("{} '{}', Status: '{}', Elapsed: '{}', Content-Type: '{}' '{}' Bytes, Reason: '{}'", - Verb, - Response.url.str(), - Response.status_code, - Response.elapsed, - ContentType, - Bytes, - Response.reason); - } - else - { - Log.debug("{} '{}', Status: '{}', Elapsed: '{}', Content-Type: '{}': '{}', Reason: '{}'", - Verb, - Response.url.str(), - Response.status_code, - Response.elapsed, - ContentType, - Response.text, - Response.reason); - } - } } // namespace detail ////////////////////////////////////////////////////////////////////////// @@ -429,7 +392,7 @@ ZenStructuredCacheSession::GetCacheRecord(std::string_view BucketId, const IoHas Session.SetHeader(cpr::Header{{"Accept", Type == ZenContentType::kCbObject ? "application/x-ue-cb" : "application/octet-stream"}}); cpr::Response Response = Session.Get(); - detail::LogResponse(m_Log, "GET"sv, Response); + m_Log.debug("GET {}", Response); if (Response.status_code == 200) { @@ -451,7 +414,7 @@ ZenStructuredCacheSession::GetCachePayload(std::string_view BucketId, const IoHa Session.SetHeader(cpr::Header{{"Accept", "application/x-ue-comp"}}); cpr::Response Response = Session.Get(); - detail::LogResponse(m_Log, "GET"sv, Response); + m_Log.debug("GET {}", Response); if (Response.status_code == 200) { @@ -475,7 +438,7 @@ ZenStructuredCacheSession::PutCacheRecord(std::string_view BucketId, const IoHas Session.SetBody(cpr::Body{static_cast<const char*>(Value.Data()), Value.Size()}); cpr::Response Response = Session.Put(); - detail::LogResponse(m_Log, "PUT"sv, Response); + m_Log.debug("PUT {}", Response); return {.Success = Response.status_code == 200}; } @@ -493,7 +456,7 @@ ZenStructuredCacheSession::PutCachePayload(std::string_view BucketId, const IoHa Session.SetBody(cpr::Body{static_cast<const char*>(Payload.Data()), Payload.Size()}); cpr::Response Response = Session.Put(); - detail::LogResponse(m_Log, "PUT"sv, Response); + m_Log.debug("PUT {}", Response); return {.Success = Response.status_code == 200}; } |