XN_C_API void xnLogWriteNoEntry(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFormat, ...) { if (!xnLogIsEnabled(csLogMask, nSeverity)) return; if (g_xnLoggerData.m_bWriteToFile) { va_list args; va_start(args, csFormat); const XnUInt32 nMaxMessageSize = 1024; XnChar csMessage[nMaxMessageSize+1]; XnUInt32 nChars; xnOSStrFormatV(csMessage, nMaxMessageSize, &nChars, csFormat, args); va_end(args); xnOSWriteFile(g_xnLoggerData.m_fLogFile, csMessage, nChars); } if (g_xnLoggerData.m_bWriteToConsole) { va_list args; va_start(args, csFormat); vprintf(csFormat, args); va_end(args); } }
XnStatus xnDumpCreate(XnDump* pDump, const XnChar* csHeader, const XnChar* csFileNameFormat, va_list args) { XnStatus nRetVal = XN_STATUS_OK; XnChar strFileName[XN_FILE_MAX_PATH]; XnUInt32 nChars; nRetVal = xnOSStrFormatV(strFileName, XN_FILE_MAX_PATH, &nChars, csFileNameFormat, args); XN_IS_STATUS_OK(nRetVal); XnChar strFullPath[XN_FILE_MAX_PATH]; nRetVal = xnLogCreateNewFile(strFileName, TRUE, strFullPath, XN_FILE_MAX_PATH, &pDump->hFile); if (nRetVal != XN_STATUS_OK) { // we don't have much to do if files can't be open. Dump will not be written xnLogWarning(XN_MASK_LOG, "Couldn't create dump file %s! Dump will not be written", strFileName); pDump->hFile = XN_INVALID_FILE_HANDLE; return nRetVal; } if (csHeader != NULL) { xnOSWriteFile(pDump->hFile, csHeader, (XnUInt32)strlen(csHeader)); } return XN_STATUS_OK; }
void xnLogWriteImplV(const XnChar* /*csLogMask*/, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, const XnChar* csFormat, va_list args) { // take time XnUInt64 nNow; xnOSGetHighResTimeStamp(&nNow); // write timestamp and severity const XnChar* csSeverity = xnLogGetSeverityString(nSeverity); const XnUInt32 nMaxMessageSize = 2047; XnChar csMessage[nMaxMessageSize+1]; XnUInt32 nChars = 0; XnUInt32 nMessageLen = 0; // write timestamp xnOSStrFormat(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%8llu\t[%s]\t", nNow, csSeverity); nMessageLen += nChars; XnUInt32 nLineInfoBegin = nMessageLen; if (g_xnLoggerData.m_bWriteLineInfo) { // write line info XnChar fileName[XN_FILE_MAX_PATH]; XnStatus nRetVal = xnOSGetFileName(csFile, fileName, sizeof(fileName)); if (nRetVal == XN_STATUS_OK) { xnOSStrFormat(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%s\t%d\t", fileName, nLine); nMessageLen += nChars; } } XnUInt32 nLineInfoEnd = nMessageLen; // write message xnOSStrFormatV(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, csFormat, args); nMessageLen += nChars; XnUInt32 nUserMsgLen = nChars; // write end-of-line xnOSStrFormat(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, XN_NEW_LINE_SEP); nMessageLen += nChars; if (g_xnLoggerData.m_bWriteToFile) { xnOSWriteFile(g_xnLoggerData.m_fLogFile, csMessage, nMessageLen); } if (g_xnLoggerData.m_bWriteToConsole) { // Write to console without line info XnChar cSaveChar = csMessage[nLineInfoBegin]; csMessage[nLineInfoBegin] = '\0'; printf("%s", csMessage); csMessage[nLineInfoBegin] = cSaveChar; //printf should know how to translate '\n' to proper newline on every platform so we don't need XN_NEW_LINE_SEP here printf("%s", csMessage + nLineInfoEnd); } }
void setErrorState(const char* strFormat, ...) { va_list args; XnUInt32 nWritten; va_start(args, strFormat); xnOSStrFormatV(g_DrawConfig.strErrorState, sizeof(g_DrawConfig.strErrorState), &nWritten, strFormat, args); va_end(args); }
XnDumpFile* xnDumpFileOpenImpl(const XnChar* strDumpName, XnBool bForce, XnBool bSessionDump, const XnChar* strNameFormat, va_list args) { XnStatus nRetVal = XN_STATUS_OK; DumpData& dumpData = DumpData::GetInstance(); // check if there are writers if (dumpData.writers.IsEmpty()) { return NULL; } if (!bForce) { if (!xnLogIsDumpMaskEnabled(strDumpName)) { return NULL; } } // format file name XnChar strFileName[XN_FILE_MAX_PATH]; XnUInt32 nChars; nRetVal = xnOSStrFormatV(strFileName, XN_FILE_MAX_PATH, &nChars, strNameFormat, args); if (nRetVal != XN_STATUS_OK) { XN_ASSERT(FALSE); return NULL; } // create a handle that will hold all handles to all writers XnDumpFile* pFile = XN_NEW(XnDumpFile); // try to add writers for (XnDumpWriters::Iterator it = dumpData.writers.Begin(); it != dumpData.writers.End(); ++it) { XnDumpWriterFile writerFile; writerFile.pWriter = *it; writerFile.hFile = writerFile.pWriter->OpenFile(writerFile.pWriter->pCookie, strDumpName, bSessionDump, strFileName); XN_ASSERT(writerFile.hFile.pInternal != NULL); if (writerFile.hFile.pInternal != NULL) { nRetVal = pFile->m_writersFiles.AddLast(writerFile); XN_ASSERT(nRetVal == XN_STATUS_OK); } } // check if any writer succeeded if (pFile->m_writersFiles.IsEmpty()) { // no file. Release memory XN_DELETE(pFile); return NULL; } // return the file pointer return pFile; }
void displayError(const char* csFormat, ...) { g_DrawConfig.messageType = ERROR_MESSAGE; g_DrawConfig.bShowMessage = true; va_list args; va_start(args, csFormat); XnUInt32 nCount; xnOSStrFormatV(g_csUserMessage, sizeof(g_csUserMessage), &nCount, csFormat, args); va_end(args); }
static void xnLogCreateEntryV(XnBufferedLogEntry* pEntry, const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, const XnChar* csFormat, va_list args) { // format message XnUInt32 nChars; xnOSStrFormatV(pEntry->Buffer(), pEntry->MaxBufferSize(), &nChars, csFormat, args); // create log entry xnOSGetHighResTimeStamp(&pEntry->nTimestamp); pEntry->nSeverity = nSeverity; pEntry->strSeverity = xnLogGetSeverityString(nSeverity); pEntry->strMask = csLogMask; pEntry->strFile = csFile; pEntry->nLine = nLine; }
XN_C_API XnStatus xnOSStrFormat(XnChar* cpDestString, const XnUInt32 nDestLength, XnUInt32* pnCharsWritten, const XnChar* cpFormat, ...) { XnStatus nRetVal = XN_STATUS_OK; va_list args; va_start(args, cpFormat); nRetVal = xnOSStrFormatV(cpDestString, nDestLength, pnCharsWritten, cpFormat, args); XN_IS_STATUS_OK(nRetVal); va_end(args); // All is good... return (XN_STATUS_OK); }
void xnLogWriteNoEntryImplV(const XnChar* csFormat, va_list args) { const XnUInt32 nMaxMessageSize = 1024; XnChar csMessage[nMaxMessageSize+1]; XnUInt32 nChars; xnOSStrFormatV(csMessage, nMaxMessageSize, &nChars, csFormat, args); LogData& logData = LogData::GetInstance(); xnl::AutoCSLocker locker(logData.hLock); for (XnLogWritersList::ConstIterator it = logData.writers.Begin(); it != logData.writers.End(); ++it) { const XnLogWriter* pWriter = *it; pWriter->WriteUnformatted(csMessage, pWriter->pCookie); } }
XN_C_API void xnDumpWriteStringImpl(XnDump dump, const XnChar* csFormat, ...) { if (dump.hFile != XN_INVALID_FILE_HANDLE) { const XnUInt32 nStringLength = 1024; XnChar csString[1024]; va_list args; va_start(args, csFormat); // format message XnUInt32 nChars; xnOSStrFormatV(csString, nStringLength, &nChars, csFormat, args); // and write it to file xnOSWriteFile(dump.hFile, csString, nChars); va_end(args); } }
XN_C_API void XN_C_DECL _xnDumpFileWriteString(XnDumpFile* pFile, const XnChar* strFormat, ...) { XnStatus nRetVal = XN_STATUS_OK; XN_REFERENCE_VARIABLE(nRetVal); if (pFile == NULL) { return; } // format string XnChar strBuffer[XN_DUMP_MAX_FORMATTED_STRING_LENGTH]; XnUInt32 nCharsWritten; va_list args; va_start(args, strFormat); nRetVal = xnOSStrFormatV(strBuffer, sizeof(strBuffer), &nCharsWritten, strFormat, args); XN_ASSERT(nRetVal == XN_STATUS_OK); va_end(args); _xnDumpFileWriteBuffer(pFile, (const XnUInt8*)strBuffer, nCharsWritten); }
XN_C_API void xnLogWriteNoEntry(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFormat, ...) { if (!xnLogIsEnabled(csLogMask, nSeverity)) return; va_list args; va_start(args, csFormat); const XnUInt32 nMaxMessageSize = 1024; XnChar csMessage[nMaxMessageSize+1]; XnUInt32 nChars; xnOSStrFormatV(csMessage, nMaxMessageSize, &nChars, csFormat, args); va_end(args); for (XnLogWritersList::ConstIterator it = g_logData.m_writers.begin(); it != g_logData.m_writers.end(); ++it) { const XnLogWriter* pWriter = *it; pWriter->WriteUnformatted(csMessage, pWriter->pCookie); } }