Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable stderr logging #50

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading