aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zencore/include/zencore/uid.h4
-rw-r--r--src/zenhttp/include/zenhttp/httpclient.h4
-rw-r--r--src/zenserver/cache/structuredcachestore.cpp75
-rw-r--r--src/zenserver/cache/structuredcachestore.h2
-rw-r--r--src/zenserver/diag/logging.cpp39
5 files changed, 111 insertions, 13 deletions
diff --git a/src/zencore/include/zencore/uid.h b/src/zencore/include/zencore/uid.h
index 9659f5893..a356da88d 100644
--- a/src/zencore/include/zencore/uid.h
+++ b/src/zencore/include/zencore/uid.h
@@ -63,8 +63,8 @@ struct Oid
void ToString(char OutString[StringLength]);
[[nodiscard]] static Oid FromMemory(const void* Ptr);
- auto operator<=>(const Oid& rhs) const = default;
- [[nodiscard]] inline operator bool() const { return *this != Zero; }
+ auto operator<=>(const Oid& rhs) const = default;
+ [[nodiscard]] inline explicit operator bool() const { return *this != Zero; }
static const Oid Zero; // Min (can be used to signify a "null" value, or for open range queries)
static const Oid Max; // Max (can be used for open range queries)
diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h
index 8ec29d548..edf3bf773 100644
--- a/src/zenhttp/include/zenhttp/httpclient.h
+++ b/src/zenhttp/include/zenhttp/httpclient.h
@@ -35,8 +35,8 @@ public:
// validate that the content type or content itself makes sense as a string.
std::string_view AsText();
- bool IsSuccess() const noexcept;
- inline operator bool() const noexcept { return IsSuccess(); }
+ bool IsSuccess() const noexcept;
+ inline explicit operator bool() const noexcept { return IsSuccess(); }
};
[[nodiscard]] Response Put(std::string_view Url, const IoBuffer& Payload);
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp
index 79f57019d..a95ae4ca2 100644
--- a/src/zenserver/cache/structuredcachestore.cpp
+++ b/src/zenserver/cache/structuredcachestore.cpp
@@ -2497,12 +2497,16 @@ ZenCacheDiskLayer::GetValueDetails(const std::string_view BucketFilter, const st
//////////////////////////// ZenCacheStore
-static constexpr std::string_view UE4DDCNamespaceName = "ue4.ddc";
+ZEN_DEFINE_LOG_CATEGORY_STATIC(LogCacheActivity, "z$");
+
+static constinit std::string_view UE4DDCNamespaceName = "ue4.ddc";
ZenCacheStore::ZenCacheStore(GcManager& Gc, const Configuration& Configuration) : m_Gc(Gc), m_Configuration(Configuration)
{
CreateDirectories(m_Configuration.BasePath);
+ ZEN_INFO("Initializing at '{}'", m_Configuration.BasePath);
+
DirectoryContent DirContent;
GetDirectoryContent(m_Configuration.BasePath, DirectoryContent::IncludeDirsFlag, DirContent);
@@ -2546,7 +2550,45 @@ ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const Io
{
if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store)
{
- return Store->Get(Bucket, HashKey, OutValue);
+ bool Result = Store->Get(Bucket, HashKey, OutValue);
+
+ if (m_Configuration.EnableAccessLog)
+ {
+ if (Result)
+ {
+ if (OutValue.Value.GetContentType() == ZenContentType::kCbObject)
+ {
+ const IoHash ObjectHash = IoHash::HashBuffer(OutValue.Value.GetView());
+ const size_t ObjectSize = OutValue.Value.GetSize();
+
+ ZEN_LOG_INFO(LogCacheActivity,
+ "GET HIT {}/{}/{} -> {} {} {}",
+ Namespace,
+ Bucket,
+ HashKey,
+ ObjectHash,
+ ObjectSize,
+ ToString(OutValue.Value.GetContentType()))
+ }
+ else
+ {
+ ZEN_LOG_INFO(LogCacheActivity,
+ "GET HIT {}/{}/{} -> {} {} {}",
+ Namespace,
+ Bucket,
+ HashKey,
+ OutValue.RawHash,
+ OutValue.RawSize,
+ ToString(OutValue.Value.GetContentType()));
+ }
+ }
+ else
+ {
+ ZEN_LOG_INFO(LogCacheActivity, "GET MISS {}/{}/{}", Namespace, Bucket, HashKey);
+ }
+ }
+
+ return Result;
}
ZEN_WARN("request for unknown namespace '{}' in ZenCacheStore::Get, bucket '{}', key '{}'", Namespace, Bucket, HashKey.ToHexString());
@@ -2556,6 +2598,35 @@ ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const Io
void
ZenCacheStore::Put(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value)
{
+ if (m_Configuration.EnableWriteLog)
+ {
+ if (Value.Value.GetContentType() == ZenContentType::kCbObject)
+ {
+ const IoHash ObjectHash = IoHash::HashBuffer(Value.Value.GetView());
+ const size_t ObjectSize = Value.Value.GetSize();
+
+ ZEN_LOG_INFO(LogCacheActivity,
+ "PUT {}/{}/{} -> {} {} {}",
+ Namespace,
+ Bucket,
+ HashKey,
+ ObjectHash,
+ ObjectSize,
+ ToString(Value.Value.GetContentType()));
+ }
+ else
+ {
+ ZEN_LOG_INFO(LogCacheActivity,
+ "PUT {}/{}/{} -> {} {} {}",
+ Namespace,
+ Bucket,
+ HashKey,
+ Value.RawHash,
+ Value.RawSize,
+ ToString(Value.Value.GetContentType()));
+ }
+ }
+
if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store)
{
return Store->Put(Bucket, HashKey, Value);
diff --git a/src/zenserver/cache/structuredcachestore.h b/src/zenserver/cache/structuredcachestore.h
index 3fb4f035d..e4f71a6cf 100644
--- a/src/zenserver/cache/structuredcachestore.h
+++ b/src/zenserver/cache/structuredcachestore.h
@@ -483,6 +483,8 @@ public:
{
std::filesystem::path BasePath;
bool AllowAutomaticCreationOfNamespaces = false;
+ bool EnableWriteLog = true;
+ bool EnableAccessLog = true;
};
struct Info
diff --git a/src/zenserver/diag/logging.cpp b/src/zenserver/diag/logging.cpp
index 24c7572f4..e6192c7c0 100644
--- a/src/zenserver/diag/logging.cpp
+++ b/src/zenserver/diag/logging.cpp
@@ -18,6 +18,8 @@ ZEN_THIRD_PARTY_INCLUDES_END
#include <zencore/compactbinary.h>
#include <zencore/filesystem.h>
+#include <zencore/fmtutils.h>
+#include <zencore/session.h>
#include <zencore/string.h>
#include <chrono>
@@ -415,30 +417,45 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
}
#endif
- // HTTP server request logging
+ std::vector<std::shared_ptr<spdlog::logger>> KnownLoggers{spdlog::default_logger()};
- std::filesystem::path HttpLogPath = GlobalOptions.DataDir / "logs" / "http.log";
+ auto RegisterLogger = [&](std::shared_ptr<spdlog::logger> Logger) {
+ spdlog::register_logger(Logger);
+ KnownLoggers.push_back(Logger);
+ };
+ // HTTP server request logging
+ std::filesystem::path HttpLogPath = GlobalOptions.DataDir / "logs" / "http.log";
// spdlog can't create directories that starts with `\\?\` so we make sure the folder exists before creating the logger instance
zen::CreateDirectories(HttpLogPath.parent_path());
-
auto HttpSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(zen::PathToUtf8(HttpLogPath),
/* max size */ 128 * 1024 * 1024,
/* max files */ 16,
/* rotate on open */ true);
auto HttpLogger = std::make_shared<spdlog::logger>("http_requests", HttpSink);
- spdlog::register_logger(HttpLogger);
+ RegisterLogger(HttpLogger);
+
+ // Cache request logging
+ std::filesystem::path CacheLogPath = GlobalOptions.DataDir / "logs" / "z$.log";
+ zen::CreateDirectories(CacheLogPath.parent_path());
+ auto CacheSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(zen::PathToUtf8(CacheLogPath),
+ /* max size */ 128 * 1024 * 1024,
+ /* max files */ 16,
+ /* rotate on open */ false);
+
+ auto CacheLogger = std::make_shared<spdlog::logger>("z$", CacheSink);
+ RegisterLogger(CacheLogger);
// Jupiter - only log upstream HTTP traffic to file
auto JupiterLogger = std::make_shared<spdlog::logger>("jupiter", FileSink);
- spdlog::register_logger(JupiterLogger);
+ RegisterLogger(JupiterLogger);
// Zen - only log upstream HTTP traffic to file
auto ZenClientLogger = std::make_shared<spdlog::logger>("zenclient", FileSink);
- spdlog::register_logger(ZenClientLogger);
+ RegisterLogger(ZenClientLogger);
// Configure all registered loggers according to settings
@@ -455,7 +472,15 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
{
FileSink->set_pattern("[%C-%m-%d.%e %T] [%n] [%l] %v");
}
- DefaultLogger.info("log starting at {}", zen::DateTime::Now().ToIso8601());
+
+ const std::string StartLogTime = zen::DateTime::Now().ToIso8601();
+ const zen::Oid ServerSessionId = zen::GetSessionId();
+
+ for (auto& Logger : KnownLoggers)
+ {
+ Logger->info("log starting at {}", StartLogTime);
+ Logger->info("server session id: {}", ServerSessionId);
+ }
}
void