XN_C_API void xnLogWriteBinaryData(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, XnUChar* pBinData, XnUInt32 nDataSize, const XnChar* csFormat, ...) { if (!xnLogIsEnabled(csLogMask, nSeverity)) return; // first write preceding message: va_list args; va_start(args, csFormat); xnLogWriteImplV(csLogMask, nSeverity, csFile, nLine, csFormat, args); va_end(args); // now write binary data (in lines of 16 bytes) XnChar csLine[256]; XnUInt32 pos = 0; for (XnUInt32 i = 0; i < nDataSize; ++i) { if ((i % 16) == 0) // first byte in line { // start a new line pos = sprintf(csLine, "%6u: ", i); } pos += sprintf(csLine + pos, "%02x ", pBinData[i]); if ((i % 16) == 15 || (i == nDataSize-1)) // last byte in line { xnLogWriteImpl(csLogMask, nSeverity, csFile, nLine, "%s", csLine); } } }
void xnLogConfigurationChanged() { // if new configuration requires a log file, and we don't have one opened if (g_xnLoggerData.m_nLogFilteringType != XN_LOG_WRITE_NONE && g_xnLoggerData.m_bWriteToFile && g_xnLoggerData.m_fLogFile == XN_INVALID_FILE_HANDLE) { XN_PROCESS_ID nProcID = 0; xnOSGetCurrentProcessID(&nProcID); XnChar strFileName[XN_FILE_MAX_PATH]; sprintf(strFileName, "%s%s_%u.log", g_xnLoggerData.m_csLogDir, g_xnLoggerData.m_csTime, nProcID); XnStatus nRetVal = xnLogCreateFile(strFileName, &g_xnLoggerData.m_fLogFile); if (nRetVal != XN_STATUS_OK) { // we don't have much to do if files can't be open. Logs will not be written to file printf("Couldn't create log file %s! Logs will not be written (error: %s)\n", strFileName, xnGetStatusString(nRetVal)); g_xnLoggerData.m_fLogFile = XN_INVALID_FILE_HANDLE; g_xnLoggerData.m_bWriteToFile = FALSE; } } if (!g_xnLoggerData.m_bBannerPrinted && xnLogIsEnabled(XN_MASK_LOG, XN_LOG_INFO)) { xnLogInfo(XN_MASK_LOG, "OpenNI version is %s", XN_VERSION_STRING); g_xnLoggerData.m_bBannerPrinted = TRUE; } if (g_xnLoggerData.m_fLogFile != XN_INVALID_FILE_HANDLE) { XnChar csMasks[XN_LOG_MASKS_STRING_LEN]; xnLogGetMasksString(csMasks); xnLogWriteImpl(XN_MASK_LOG, XN_LOG_INFO, __FILE__, __LINE__, "Log system initialized. Console: %d, File: %d, Severity: %s, Masks: %s", g_xnLoggerData.m_bWriteToConsole, g_xnLoggerData.m_bWriteToFile, xnLogGetSeverityString(g_xnLoggerData.m_nFilterSeverity), csMasks); } }