On Windows, running mediaserver.exe directly from the console (for example, with mediaserver.exe -e) does not display standard output (stdout) or standard error (stderr) in the terminal. This is a design characteristic of the Windows platform.
This guide explains how to enable the OutputRedirector mechanism to capture this output in log files, and how to configure logging for your custom plugins.
NOTE: The OutputRedirector mechanism does not work on Windows if your plugin is built using the Debug build configuration. In this configuration, stdout and stderr are lost. Use a Release build (or Release with Debug Info) when you test or profile your code. |
Step 1: Locate or create the nx_ini directory
The redirection files must reside in a specific directory named nx_ini. Because the system does not create this directory automatically, you must create it manually.
The directory path depends on how you run the Media Server:
Running as a Service (Default):
C:\Windows\System32\config\systemprofile\AppData\Local\nx_ini\Running from the Console or User Session:
C:\Users\<Your_User>\AppData\Local\nx_ini\
NOTE: To verify the exact expected path on your system, call the /api/iniConfig API endpoint. |
Step 2: Enable server output redirection
To redirect the Media Server outputs to log files:
Navigate to the
nx_inidirectory you identified in Step 1.Create two empty text files in that directory with these exact names:
mediaserver_stdout.logmediaserver_stderr.log
Restart the Media Server.
What the logs contain
mediaserver_stdout.log: Typically remains around 1 KB. It contains a single initialization string that confirms the redirection works.mediaserver_stderr.log: Contains the actual runtime logs, server output, and plugin logs. The system writes tostderrbecause it is unbuffered, which prevents log collision.
| NOTE: The system overwrites these log files every time the Media Server restarts. |
Step 3: Enable output for your plugin
If you develop a plugin using nx_kit and want to view its log statements:
In your
nx_inidirectory, create an empty configuration file named after your plugin. Use the format<plugin_name>.ini(for example,stub_analytics_plugin.ini).Restart the Media Server. The server automatically populates this
.inifile with configuration fields.Open the
.inifile and set the following value:enableOutput=trueRestart the Media Server again to apply the configuration.
Developer guide: Log with nx_kit
The nx_kit framework provides macros inside <nx/kit/debug.h> to manage console logging. These macros automatically append newlines and prefix the output with the origin filename.
1. Log levels
NX_PRINT: Prints unconditionally tostderr. Use this as your standard log level.NX_OUTPUT: Prints tostderronly if you enable verbose output. You can enable this by settingenableOutput=truein your.inifile, or by definingNX_DEBUG_ENABLE_OUTPUTbefore you include the header.
2. Implementation example
Define your configuration in your header file:
// my_module_ini.h
#include <nx/kit/ini_config.h>
struct Ini: nx::kit::IniConfig
{
Ini(): IniConfig("my_module.ini") { reload(); }
NX_INI_FLAG(0, enableOutput, "Whether to produce verbose log on stderr.");
};
inline Ini& ini()
{
static Ini ini;
return ini;
}Use the macros in your source file:
// my_module.cpp
#include "my_module_ini.h"
#include <nx/kit/debug.h>
void func()
{
// Prints unconditionally
NX_PRINT << "Printed unconditionally.";
// Prints only if my_module.ini contains "enableOutput=1"
NX_OUTPUT << "Printed only if verbose output is enabled.";
}This code generates the following output in mediaserver_stderr.log:
[my_module.cpp] Printed unconditionally.
[my_module.cpp] Printed only if verbose output is enabled.Best practices and troubleshooting
Search logs quickly
Because plugin initialization occurs early in the startup procedure, log files can grow quickly. To find your logs easily, prefix your debug lines with a unique keyword, such as ZZZZ:
NX_PRINT << "ZZZZ [Debug] My variable value: " << myVar;You can then filter the log file in the Windows Command Prompt using the find command:
find /i "ZZZZ" C:\path\to\nx_ini\mediaserver_stderr.logVerify that the plugin loaded
If you do not see any output, confirm that the server actually loaded your plugin. Search mediaserver_stderr.log for PluginManager messages to verify a successful initialization.
Comments
0 comments
Article is closed for comments.