aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/zenserver.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-09-26 09:54:00 +0200
committerStefan Boberg <[email protected]>2023-09-26 09:54:00 +0200
commit6b23bf09acd11f50ec224297ee69bef15cad39ee (patch)
tree8b2bcfe89eb5ffd71cae323dc62c4881024aa876 /src/zenserver/zenserver.cpp
parentsort commands for cleaner merges (diff)
parent0.2.24 (diff)
downloadzen-6b23bf09acd11f50ec224297ee69bef15cad39ee.tar.xz
zen-6b23bf09acd11f50ec224297ee69bef15cad39ee.zip
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'src/zenserver/zenserver.cpp')
-rw-r--r--src/zenserver/zenserver.cpp100
1 files changed, 65 insertions, 35 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 921e3038d..40a797c21 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -161,13 +161,31 @@ namespace utils {
void sink_it_(const spdlog::details::log_msg& msg) override
{
- std::string Message = fmt::format("{}\n{}({}) [{}]", msg.payload, msg.source.filename, msg.source.line, msg.source.funcname);
- sentry_value_t event = sentry_value_new_message_event(
- /* level */ MapToSentryLevel[msg.level],
- /* logger */ nullptr,
- /* message */ Message.c_str());
- sentry_event_value_add_stacktrace(event, NULL, 0);
- sentry_capture_event(event);
+ try
+ {
+ std::string Message =
+ fmt::format("{}\n{}({}) [{}]", msg.payload, msg.source.filename, msg.source.line, msg.source.funcname);
+ sentry_value_t event = sentry_value_new_message_event(
+ /* level */ MapToSentryLevel[msg.level],
+ /* logger */ nullptr,
+ /* message */ Message.c_str());
+ sentry_event_value_add_stacktrace(event, NULL, 0);
+ sentry_capture_event(event);
+ }
+ catch (std::exception&)
+ {
+ // If our logging with Message formatting fails we do a non-allocating version and just post the msg.payload raw
+ char TmpBuffer[256];
+ size_t MaxCopy = Min<size_t>(msg.payload.size(), size_t(255));
+ memcpy(TmpBuffer, msg.payload.data(), MaxCopy);
+ TmpBuffer[MaxCopy] = '\0';
+ sentry_value_t event = sentry_value_new_message_event(
+ /* level */ SENTRY_LEVEL_ERROR,
+ /* logger */ nullptr,
+ /* message */ TmpBuffer);
+ sentry_event_value_add_stacktrace(event, NULL, 0);
+ sentry_capture_event(event);
+ }
}
void flush_() override {}
};
@@ -181,13 +199,26 @@ namespace utils {
const char* FunctionName,
const char* Msg)
{
- std::string Message = fmt::format("ASSERT {}:({}) [{}]\n\"{}\"", Filename, LineNumber, FunctionName, Msg);
- sentry_value_t event = sentry_value_new_message_event(
- /* level */ SENTRY_LEVEL_ERROR,
- /* logger */ nullptr,
- /* message */ Message.c_str());
- sentry_event_value_add_stacktrace(event, NULL, 0);
- sentry_capture_event(event);
+ try
+ {
+ std::string Message = fmt::format("ASSERT {}:({}) [{}]\n\"{}\"", Filename, LineNumber, FunctionName, Msg);
+ sentry_value_t event = sentry_value_new_message_event(
+ /* level */ SENTRY_LEVEL_ERROR,
+ /* logger */ nullptr,
+ /* message */ Message.c_str());
+ sentry_event_value_add_stacktrace(event, NULL, 0);
+ sentry_capture_event(event);
+ }
+ catch (std::exception&)
+ {
+ // If our logging with Message formatting fails we do a non-allocating version and just post the Msg raw
+ sentry_value_t event = sentry_value_new_message_event(
+ /* level */ SENTRY_LEVEL_ERROR,
+ /* logger */ nullptr,
+ /* message */ Msg);
+ sentry_event_value_add_stacktrace(event, NULL, 0);
+ sentry_capture_event(event);
+ }
}
AssertImpl* PrevAssertImpl;
};
@@ -433,7 +464,13 @@ public:
m_GcScheduler.Initialize(GcConfig);
// Create and register admin interface last to make sure all is properly initialized
- m_AdminService = std::make_unique<HttpAdminService>(m_GcScheduler, *m_JobQueue);
+ m_AdminService =
+ std::make_unique<HttpAdminService>(m_GcScheduler,
+ *m_JobQueue,
+ *m_CacheStore,
+ HttpAdminService::LogPaths{.AbsLogPath = ServerOptions.AbsLogFile,
+ .HttpLogPath = ServerOptions.DataDir / "logs" / "http.log",
+ .CacheLogPath = ServerOptions.DataDir / "logs" / "z$.log"});
m_Http->RegisterService(*m_AdminService);
return EffectiveBasePort;
@@ -905,12 +942,13 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
using namespace std::literals;
ZEN_INFO("instantiating structured cache service");
- m_CacheStore = new ZenCacheStore(m_GcManager,
- ZenCacheStore::Configuration{.BasePath = m_DataRoot / "cache",
- .AllowAutomaticCreationOfNamespaces = true,
- .EnableWriteLog = ServerOptions.StructuredCacheWriteLogEnabled,
- .EnableAccessLog = ServerOptions.StructuredCacheAccessLogEnabled},
- m_GcManager.GetDiskWriteBlocker());
+ m_CacheStore =
+ new ZenCacheStore(m_GcManager,
+ ZenCacheStore::Configuration{.BasePath = m_DataRoot / "cache",
+ .AllowAutomaticCreationOfNamespaces = true,
+ .Logging = {.EnableWriteLog = ServerOptions.StructuredCacheWriteLogEnabled,
+ .EnableAccessLog = ServerOptions.StructuredCacheAccessLogEnabled}},
+ m_GcManager.GetDiskWriteBlocker());
const ZenUpstreamCacheConfig& UpstreamConfig = ServerOptions.UpstreamCacheConfig;
@@ -1136,7 +1174,7 @@ ZenEntryPoint::Run()
sentry_options_set_dsn(SentryOptions, "https://[email protected]/5919284");
sentry_options_set_database_path(SentryOptions, SentryDatabasePath.c_str());
sentry_options_set_logger(SentryOptions, SentryLogFunction, this);
- std::string SentryAttachmentPath = m_ServerOptions.AbsLogFile.string();
+ std::string SentryAttachmentPath = PathToUtf8(m_ServerOptions.AbsLogFile);
if (SentryAttachmentPath.starts_with("\\\\?\\"))
{
SentryAttachmentPath = SentryAttachmentPath.substr(4);
@@ -1186,8 +1224,8 @@ ZenEntryPoint::Run()
auto _ = zen::MakeGuard([&SentryAssert, SentryErrorCode] {
if (SentryErrorCode == 0)
{
- SentryAssert.reset();
zen::logging::SetErrorLog(std::shared_ptr<spdlog::logger>());
+ SentryAssert.reset();
sentry_close();
}
});
@@ -1420,14 +1458,6 @@ test_main(int argc, char** argv)
}
#endif
-#if ZEN_WITH_TRACE
-static void
-StopTrace()
-{
- TraceShutdown();
-}
-#endif // ZEN_WITH_TRACE
-
int
main(int argc, char* argv[])
{
@@ -1466,17 +1496,17 @@ main(int argc, char* argv[])
#if ZEN_WITH_TRACE
if (ServerOptions.TraceHost.size())
{
- TraceInit(ServerOptions.TraceHost.c_str(), TraceType::Network);
+ TraceStart(ServerOptions.TraceHost.c_str(), TraceType::Network);
}
else if (ServerOptions.TraceFile.size())
{
- TraceInit(ServerOptions.TraceFile.c_str(), TraceType::File);
+ TraceStart(ServerOptions.TraceFile.c_str(), TraceType::File);
}
else
{
- TraceInit(nullptr, TraceType::None);
+ TraceInit();
}
- atexit(StopTrace);
+ atexit(TraceShutdown);
#endif // ZEN_WITH_TRACE
#if ZEN_PLATFORM_WINDOWS