Is the Nx Cloud up? Visit our Status Page for the current health and performance of the Nx Cloud.

Status Page

How to display NX_PRINTF logs in debug builds?

Comments

1 comment

  • Ichiro
    • Network Optix team

    Hi

    I think you're saying NX_PRINT, as we don't have NX_PRINTF method.

    If you check the SDK, then looking at nx_kit/src/nx/kit/debug.h and debug.cpp:

    • NX_PRINT (and everything built on it, ex: NX_PRINT_VALUE, NX_PRINT_HEX_DUMP, assertion failures) writes unconditionally to nx::kit::debug::stream(), which defaults to std::cerr

       

    • NX_OUTPUT is the toggleable version — it only prints if (NX_DEBUG_ENABLE_OUTPUT), which by default resolves to ini().enableOutput.

    So if your debug statements use NX_PRINT directly (or macros derived from it), turning off any "debug" flag won't help — they always fire.

     

    Option 1 - use the built-in enableOutput switch (recommended)

    If your logging goes through NX_OUTPUT (via the Engine/ConsumingDeviceAgent base classes in nx/sdk/analytics/helpers/), it's already gated by a constructor flag. In the sample plugin this is hardcoded on:

    // engine.cpp 
    Engine::Engine():     
        nx::sdk::analytics::Engine(/*enableOutput*/ true)   // <-- flip to false 
    {
    }
    // device_agent.cpp 
    ConsumingDeviceAgent(deviceInfo, /*enableOutput*/ true) // <-- flip to false

    Setting these to false (or driving them from your own build config / .ini flag) silences all NX_OUTPUT calls without touching source elsewhere.

     

    Option 2 — Strip or guard your NX_PRINT calls

    Since NX_PRINT is unconditional by design (it's meant for things you always want logged, like errors), the clean fix for pure debugging prints is to remove them before shipping, or wrap them yourself:

    #ifdef MY_PLUGIN_DEBUG_LOGGING     
        NX_PRINT << "some debug value: " << value; 
    #endif

    and simply don't define MY_PLUGIN_DEBUG_LOGGING in your release build.

     

    Note for IniConfig

    If your plugin defines its own .ini (via nx::kit::IniConfig), double-check it isn't shipping with enableOutput=true written into the .ini file in your output directory — IniConfig::reload() will re-enable output from that file even if your constructor default is false. Set/lock it to false there too, or disable .ini reading for the release build (IniConfig has an option to freeze values instead of reloading — see ini_config.h).

     

    For a quick fix, do Option 1 for anything going through the Engine/ConsumingDeviceAgent helpers, and grep your plugin for raw NX_PRINT/LL/NX_PRINT_VALUE calls you added while debugging and delete.

     

     

     

     

     

    0

Please sign in to leave a comment.