// Copyright Epic Games, Inc. All Rights Reserved. #include "logging.h" #include "config/config.h" #include #include #include #include #include #include #include #include "otlphttp.h" ZEN_THIRD_PARTY_INCLUDES_START #include ZEN_THIRD_PARTY_INCLUDES_END namespace zen { void InitializeServerLogging(const ZenServerConfig& InOptions, bool WithCacheService) { ZEN_MEMSCOPE(ELLMTag::Logging); const LoggingOptions LogOptions = {.IsDebug = InOptions.IsDebug, .IsVerbose = false, .IsTest = InOptions.IsTest, .NoConsoleOutput = InOptions.LoggingConfig.NoConsoleOutput, .QuietConsole = InOptions.LoggingConfig.QuietConsole, .AbsLogFile = InOptions.LoggingConfig.AbsLogFile, .LogId = InOptions.LoggingConfig.LogId}; BeginInitializeLogging(LogOptions); // Initialize loggers auto FileSink = GetFileSink(); // HTTP server request logging std::filesystem::path HttpLogPath = InOptions.DataDir / "logs" / "http.log"; zen::CreateDirectories(HttpLogPath.parent_path()); auto HttpSink = std::make_shared(HttpLogPath, /* max size */ 128 * 1024 * 1024, /* max files */ 16, /* rotate on open */ true); auto HttpLogger = std::make_shared("http_requests", HttpSink); spdlog::apply_logger_env_levels(HttpLogger); spdlog::register_logger(HttpLogger); if (WithCacheService) { // Cache request logging std::filesystem::path CacheLogPath = InOptions.DataDir / "logs" / "z$.log"; zen::CreateDirectories(CacheLogPath.parent_path()); auto CacheSink = std::make_shared(CacheLogPath, /* max size */ 128 * 1024 * 1024, /* max files */ 16, /* rotate on open */ false); auto CacheLogger = std::make_shared("z$", CacheSink); spdlog::apply_logger_env_levels(CacheLogger); spdlog::register_logger(CacheLogger); // Jupiter - only log upstream HTTP traffic to file auto JupiterLogger = std::make_shared("jupiter", FileSink); spdlog::apply_logger_env_levels(JupiterLogger); spdlog::register_logger(JupiterLogger); // Zen - only log upstream HTTP traffic to file auto ZenClientLogger = std::make_shared("zenclient", FileSink); spdlog::apply_logger_env_levels(ZenClientLogger); spdlog::register_logger(ZenClientLogger); } #if ZEN_WITH_OTEL if (!InOptions.LoggingConfig.OtelEndpointUri.empty()) { // TODO: Should sanity check that endpoint is reachable? Also, a valid URI? auto OtelSink = std::make_shared(InOptions.LoggingConfig.OtelEndpointUri); zen::logging::Default().SpdLogger->sinks().push_back(std::move(OtelSink)); } #endif FinishInitializeLogging(LogOptions); const zen::Oid ServerSessionId = zen::GetSessionId(); spdlog::apply_all([&](auto Logger) { ZEN_MEMSCOPE(ELLMTag::Logging); Logger->info("server session id: {}", ServerSessionId); }); } void ShutdownServerLogging() { ZEN_MEMSCOPE(ELLMTag::Logging); zen::ShutdownLogging(); } } // namespace zen