aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/upstream
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-11-06 20:36:30 +0100
committerGitHub <[email protected]>2023-11-06 20:36:30 +0100
commit07f288d6e119fc6bb524fb634bc9094109a2ab05 (patch)
tree8531bd38d0d8c3567ba3d0a5603f549faf99632b /src/zenserver/upstream
parentgc v2 tests (#512) (diff)
downloadzen-07f288d6e119fc6bb524fb634bc9094109a2ab05.tar.xz
zen-07f288d6e119fc6bb524fb634bc9094109a2ab05.zip
spdlog implementation hiding (#498)
this change aims to hide logging internals from client code, in order to make it easier to extend and take more control over the logging process in the future. As a bonus side effect, the generated code is much tighter (net delta around 2.5% on the resulting executable which includes lots of thirdparty code) and should take less time to compile and link. Client usage via macros is pretty much unchanged. The main exposure client code had to spdlog internals before was the use of custom loggers per subsystem, where it would be common to have `spdlog::logger` references to keep a reference to a logger within a class. This is now replaced by `zen::LoggerRef` which currently simply encapsulates an actual `spdlog::logger` instance, but this is intended to be an implementation detail which will change in the future. The way the change works is that we now handle any formatting of log messages in the zencore logging subsystem instead of relying on `spdlog` to manage this. We use the `fmt` library to do the formatting which means the client usage is identical to using `spdlog`. The formatted message is then forwarded onto any sinks etc which are still implememted via `spdlog`.
Diffstat (limited to 'src/zenserver/upstream')
-rw-r--r--src/zenserver/upstream/jupiter.h12
-rw-r--r--src/zenserver/upstream/upstreamcache.cpp13
-rw-r--r--src/zenserver/upstream/zen.h12
3 files changed, 16 insertions, 21 deletions
diff --git a/src/zenserver/upstream/jupiter.h b/src/zenserver/upstream/jupiter.h
index ca84905d2..467f28501 100644
--- a/src/zenserver/upstream/jupiter.h
+++ b/src/zenserver/upstream/jupiter.h
@@ -131,15 +131,15 @@ public:
CloudCacheClient& Client() { return *m_CacheClient; };
private:
- inline spdlog::logger& Log() { return m_Log; }
- cpr::Session& GetSession();
- CloudCacheAccessToken GetAccessToken(bool RefreshToken = false);
+ inline LoggerRef Log() { return m_Log; }
+ cpr::Session& GetSession();
+ CloudCacheAccessToken GetAccessToken(bool RefreshToken = false);
CloudCacheResult CacheTypeExists(std::string_view Namespace, std::string_view TypeId, const IoHash& Key);
CloudCacheExistsResult CacheTypeExists(std::string_view Namespace, std::string_view TypeId, const std::set<IoHash>& Keys);
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
RefPtr<CloudCacheClient> m_CacheClient;
detail::CloudCacheSessionState* m_SessionState;
};
@@ -195,10 +195,10 @@ public:
std::string_view ComputeCluster() const { return m_ComputeCluster; }
std::string_view ServiceUrl() const { return m_ServiceUrl; }
- spdlog::logger& Logger() { return m_Log; }
+ LoggerRef Logger() { return m_Log; }
private:
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
std::string m_ServiceUrl;
std::string m_DefaultDdcNamespace;
std::string m_DefaultBlobStoreNamespace;
diff --git a/src/zenserver/upstream/upstreamcache.cpp b/src/zenserver/upstream/upstreamcache.cpp
index 5f711d0bc..8e00f86b0 100644
--- a/src/zenserver/upstream/upstreamcache.cpp
+++ b/src/zenserver/upstream/upstreamcache.cpp
@@ -29,7 +29,6 @@
#include <atomic>
#include <shared_mutex>
#include <thread>
-#include <unordered_map>
namespace zen {
@@ -753,10 +752,10 @@ namespace detail {
return {.Bytes = TotalBytes, .ElapsedSeconds = TotalElapsedSeconds, .Success = true};
}
- spdlog::logger& Log() { return m_Log; }
+ LoggerRef Log() { return m_Log; }
AuthMgr& m_AuthMgr;
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
UpstreamEndpointInfo m_Info;
UpstreamStatus m_Status;
UpstreamEndpointStats m_Stats;
@@ -1460,9 +1459,9 @@ namespace detail {
return m_Endpoints.front();
}
- spdlog::logger& Log() { return m_Log; }
+ LoggerRef Log() { return m_Log; }
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
UpstreamEndpointInfo m_Info;
UpstreamStatus m_Status;
UpstreamEndpointStats m_Stats;
@@ -2078,7 +2077,7 @@ private:
}
}
- spdlog::logger& Log() { return m_Log; }
+ LoggerRef Log() { return m_Log; }
using UpstreamQueue = BlockingQueue<UpstreamCacheRecord>;
@@ -2103,7 +2102,7 @@ private:
}
};
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
UpstreamCacheOptions m_Options;
ZenCacheStore& m_CacheStore;
CidStore& m_CidStore;
diff --git a/src/zenserver/upstream/zen.h b/src/zenserver/upstream/zen.h
index bfba8fa98..c1e4fbd0f 100644
--- a/src/zenserver/upstream/zen.h
+++ b/src/zenserver/upstream/zen.h
@@ -20,10 +20,6 @@ ZEN_THIRD_PARTY_INCLUDES_END
struct ZenCacheValue;
-namespace spdlog {
-class logger;
-}
-
namespace zen {
class CbObjectWriter;
@@ -85,9 +81,9 @@ public:
ZenCacheResult InvokeRpc(const CbPackage& Package);
private:
- inline spdlog::logger& Log() { return m_Log; }
+ inline LoggerRef Log() { return m_Log; }
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
Ref<ZenStructuredCacheClient> m_Client;
detail::ZenCacheSessionState* m_SessionState;
};
@@ -105,10 +101,10 @@ public:
std::string_view ServiceUrl() const { return m_ServiceUrl; }
- inline spdlog::logger& Log() { return m_Log; }
+ inline LoggerRef Log() { return m_Log; }
private:
- spdlog::logger& m_Log;
+ LoggerRef m_Log;
std::string m_ServiceUrl;
std::chrono::milliseconds m_ConnectTimeout;
std::chrono::milliseconds m_Timeout;