Skip to content

Commit

Permalink
Enable stderr logging (#50)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
foodprocessor committed Aug 22, 2024
1 parent 0969522 commit 70b03e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/plugin/settings/device_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <algorithm>

#define NX_PRINT_PREFIX (this->logUtils.printPrefix)
#include <nx/kit/debug.h>
#include <nx/kit/utils.h>
#include <nx/sdk/helpers/active_setting_changed_response.h>
Expand Down
28 changes: 27 additions & 1 deletion src/plugin/settings/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <algorithm>
#include <chrono>
#include <filesystem>
#include <fstream>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
Expand All @@ -21,8 +22,8 @@

#include "cloudfuse_helper.h"

#define NX_PRINT_PREFIX (this->logUtils.printPrefix)
#include <nx/kit/debug.h>
#include <nx/kit/ini_config.h>
#include <nx/sdk/helpers/active_setting_changed_response.h>
#include <nx/sdk/helpers/error.h>
#include <utils.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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<std::string, std::string> *values,
const std::vector<std::string> &settingIdsToUpdate) const
{
Expand Down

0 comments on commit 70b03e3

Please sign in to comment.