added debug flag for background log writer
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 9 Jun 2016 19:29:59 +0000 (22:29 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 9 Jun 2016 19:29:59 +0000 (22:29 +0300)
include/nms_util.h
src/libnetxms/log.cpp

index 9d7266d..fc749ed 100644 (file)
@@ -143,6 +143,7 @@ void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
 #define NXLOG_USE_SYSLOG                 ((UINT32)0x00000001)
 #define NXLOG_PRINT_TO_STDOUT    ((UINT32)0x00000002)
 #define NXLOG_BACKGROUND_WRITER ((UINT32)0x00000004)
+#define NXLOG_DEBUG_MODE        ((UINT32)0x00000008)
 #define NXLOG_IS_OPEN           ((UINT32)0x80000000)
 
 /**
index a6c737b..327e16f 100644 (file)
@@ -285,10 +285,23 @@ static THREAD_RESULT THREAD_CALL BackgroundWriterThread(void *arg)
          if (m_flags & NXLOG_PRINT_TO_STDOUT)
             m_consoleWriter(_T("%s"), s_logBuffer.getBuffer());
 
+         size_t buflen = s_logBuffer.length();
          char *data = s_logBuffer.getUTF8String();
          s_logBuffer.clear();
          MutexUnlock(m_mutexLogAccess);
 
+         if (m_flags & NXLOG_DEBUG_MODE)
+         {
+            char marker[64];
+            sprintf(marker, "##(" INT64_FMTA ")" INT64_FMTA " @" INT64_FMTA "\n",
+                    (INT64)buflen, (INT64)strlen(data), GetCurrentTimeMs());
+#ifdef _WIN32
+            fwrite(marker, 1, strlen(marker), m_logFileHandle);
+#else
+            write(fileno(m_logFileHandle), marker, strlen(marker));
+#endif
+         }
+
 #ifdef _WIN32
                        fwrite(data, 1, strlen(data), m_logFileHandle);
 #else