aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zenserver/diag/logging.cpp9
-rw-r--r--zenstore/filecas.cpp84
2 files changed, 13 insertions, 80 deletions
diff --git a/zenserver/diag/logging.cpp b/zenserver/diag/logging.cpp
index 2bf0e50aa..2583784c3 100644
--- a/zenserver/diag/logging.cpp
+++ b/zenserver/diag/logging.cpp
@@ -4,8 +4,10 @@
#include "config.h"
+#include <zencore/string.h>
#include <spdlog/pattern_formatter.h>
#include <spdlog/sinks/ansicolor_sink.h>
+#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <memory>
@@ -186,9 +188,16 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
{
EnableVTMode();
+ std::filesystem::path LogPath = GlobalOptions.DataDir / "logs/zenserver.txt";
+
+ auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(zen::WideToUtf8(LogPath.c_str()), /* truncate */ true);
+ file_sink->set_level(spdlog::level::trace);
+
auto& sinks = spdlog::default_logger()->sinks();
sinks.clear();
sinks.push_back(std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>());
+ sinks.push_back(file_sink);
+
spdlog::set_level(spdlog::level::debug);
spdlog::set_formatter(std::make_unique<logging::full_formatter>(GlobalOptions.LogId, std::chrono::system_clock::now()));
}
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index 845206741..7465e5182 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -17,13 +17,10 @@
#include <functional>
#include <unordered_map>
-// clang-format off
#include <zencore/prewindows.h>
struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error: 'identifier' was unexpected here" when using /permissive-
#include <atlfile.h>
-#include <ShlObj.h> // Used for getting My Documents for default CAS
-#pragma comment(lib, "shell32.lib")
#include <zencore/postwindows.h>
// clang-format on
@@ -100,14 +97,12 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash)
{
CAtlFile PayloadFile;
- HRESULT hRes = PayloadFile.Create(ShardedPath.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);
-
- if (SUCCEEDED(hRes))
+ if (HRESULT hRes = PayloadFile.Create(ShardedPath.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); SUCCEEDED(hRes))
{
- // If we succeeded in opening the file then we don't need to do anything else because it already exists and should contain
- // the content we were about to insert
+ // If we succeeded in opening the target file then we don't need to do anything else because it already exists
+ // and should contain the content we were about to insert
- // We do need to ensure the file goes away on close, however
+ // We do need to ensure the source file goes away on close, however
DeletePayloadFileOnClose();
@@ -362,75 +357,4 @@ FileCasStrategy::GarbageCollect(GcContext& GcCtx)
{
}
-/**
- * Straightforward file-per-chunk CAS store implementation
- */
-class FileCasImpl : public CasStore
-{
-public:
- FileCasImpl() : m_Strategy(m_Config, m_Stats) {}
- virtual ~FileCasImpl() = default;
-
- void PickDefaultDirectory()
- {
- if (m_Config.RootDirectory.empty())
- {
- // Pick sensible default
-
- WCHAR myDocumentsDir[MAX_PATH];
- HRESULT hRes = SHGetFolderPathW(NULL,
- CSIDL_PERSONAL /* My Documents */,
- NULL,
- SHGFP_TYPE_CURRENT,
- /* out */ myDocumentsDir);
-
- if (SUCCEEDED(hRes))
- {
- wcscat_s(myDocumentsDir, L"\\zen\\DefaultCAS");
-
- m_Config.RootDirectory = myDocumentsDir;
- }
- }
- }
-
- virtual void Initialize(const CasStoreConfiguration& InConfig) override
- {
- m_Config = InConfig;
-
- if (m_Config.RootDirectory.empty())
- {
- PickDefaultDirectory();
- }
-
- // Ensure root directory exists - create if it doesn't exist already
-
- std::filesystem::create_directories(m_Config.RootDirectory);
-
- std::filesystem::path filepath = m_Config.RootDirectory;
- filepath /= ".cas_root";
-
- CAtlFile marker;
- HRESULT hRes = marker.Create(filepath.c_str(), GENERIC_READ, 0, OPEN_EXISTING);
-
- if (FAILED(hRes))
- {
- ExtendableStringBuilder<128> manifest;
- manifest.Append("CAS_ROOT");
- hRes = marker.Create(filepath.c_str(), GENERIC_WRITE, 0, CREATE_ALWAYS);
-
- if (SUCCEEDED(hRes))
- marker.Write(manifest.c_str(), (DWORD)manifest.Size());
- }
- }
-
- virtual CasStore::InsertResult InsertChunk(IoBuffer Chunk, const IoHash& chunkHash) override
- {
- return m_Strategy.InsertChunk(Chunk, chunkHash);
- }
- virtual IoBuffer FindChunk(const IoHash& chunkHash) override { return m_Strategy.FindChunk(chunkHash); }
-
-private:
- FileCasStrategy m_Strategy;
-};
-
} // namespace zen