From 70b03e307d729ade66fc8c46d8704d7340502fa5 Mon Sep 17 00:00:00 2001 From: Michael Habinsky Date: Thu, 22 Aug 2024 09:53:08 -0600 Subject: [PATCH] Enable stderr logging (#50) * Create files to capture server output for plugin logging. * Remove redefinition of NX_PRINT_PREFIX which was causing compile errors when printing outside of member functions. --- src/plugin/settings/device_agent.cpp | 1 - src/plugin/settings/engine.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plugin/settings/device_agent.cpp b/src/plugin/settings/device_agent.cpp index 8f50e5d..a89fff0 100644 --- a/src/plugin/settings/device_agent.cpp +++ b/src/plugin/settings/device_agent.cpp @@ -5,7 +5,6 @@ #include -#define NX_PRINT_PREFIX (this->logUtils.printPrefix) #include #include #include diff --git a/src/plugin/settings/engine.cpp b/src/plugin/settings/engine.cpp index 20f438a..c612094 100644 --- a/src/plugin/settings/engine.cpp +++ b/src/plugin/settings/engine.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -21,8 +22,8 @@ #include "cloudfuse_helper.h" -#define NX_PRINT_PREFIX (this->logUtils.printPrefix) #include +#include #include #include #include @@ -40,10 +41,15 @@ using namespace nx::sdk; using namespace nx::sdk::analytics; using namespace nx::kit; +void enableLogging(std::string iniDir); + Engine::Engine(Plugin *plugin) : nx::sdk::analytics::Engine(NX_DEBUG_ENABLE_OUTPUT, plugin->instanceId()), m_plugin(plugin), cfManager() { + // logging will begin the _next_ time the mediaserver starts + enableLogging(IniConfig::iniFilesDir()); NX_PRINT << "cloudfuse Engine::Engine"; + for (const auto &entry : kActiveSettingsRules) { const ActiveSettingsBuilder::ActiveSettingKey key = entry.first; @@ -105,6 +111,26 @@ std::string Engine::manifestString() const return result; } +void enableLogging(std::string iniDir) +{ + // enable logging by touching stdout and stderr redirect files + if (!fs::is_directory(iniDir)) + { + fs::create_directories(iniDir); + } + const std::string processName = utils::getProcessName(); + const std::string stdoutFilename = iniDir + processName + "_stdout.log"; + const std::string stderrFilename = iniDir + processName + "_stderr.log"; + if (!fs::exists(stdoutFilename) || !fs::exists(stderrFilename)) + { + NX_PRINT << "cloudfuse Engine::enableLogging - creating files"; + std::ofstream stdoutFile(stdoutFilename); + std::ofstream stderrFile(stderrFilename); + // the service will need to be restarted for logging to actually begin + } + NX_PRINT << "cloudfuse Engine::enableLogging - plugin stderr logging file: " + stderrFilename; +} + bool Engine::processActiveSettings(Json::object *model, std::map *values, const std::vector &settingIdsToUpdate) const {