|
@@ -5,6 +5,8 @@
|
|
|
#include <iostream>
|
|
|
#include <exception>
|
|
|
|
|
|
+#include "log_process_module.h"
|
|
|
+
|
|
|
using namespace std;
|
|
|
//#include <thread>
|
|
|
//#include <mutex>
|
|
@@ -25,6 +27,10 @@ unsigned nSqlThreadID[SQL_PROCESS_THREAD_NUM];
|
|
|
HANDLE hErrLogThread[ERR_LOG_PROCESS_THREAD_NUM];
|
|
|
unsigned nErrLogThreadID[ERR_LOG_PROCESS_THREAD_NUM];
|
|
|
|
|
|
+HANDLE hSysLogThread[SYS_LOG_PROCESS_THREAD_NUM];
|
|
|
+unsigned nSysLogThreadID[SYS_LOG_PROCESS_THREAD_NUM];
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -285,7 +291,6 @@ int send_err_log_message(char* pchr)
|
|
|
unsigned thread_id = rand() % ERR_LOG_PROCESS_THREAD_NUM;
|
|
|
if(!PostThreadMessage(nErrLogThreadID[thread_id], ERR_LOG_MSG, (WPARAM)pchr, 0))//post thread msg
|
|
|
{
|
|
|
- PostThreadMessage(nErrLogThreadID[thread_id], ERR_LOG_MSG, (WPARAM)pchr, 0);
|
|
|
printf("post message failed,errno:%d\n",::GetLastError());
|
|
|
delete[] pchr;
|
|
|
return 1;
|
|
@@ -293,6 +298,51 @@ int send_err_log_message(char* pchr)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+int sys_log_process_thread_init()
|
|
|
+{
|
|
|
+ int i = 0;
|
|
|
+ log_module_init();
|
|
|
+ for(i=0; i<SYS_LOG_PROCESS_THREAD_NUM; i++)
|
|
|
+ {
|
|
|
+ hSysLogThread[i] = (HANDLE)_beginthreadex( NULL, 0, &sys_log_process_entry, NULL, 0, &(nSysLogThreadID[i]) );
|
|
|
+ if(hSysLogThread[i] == 0)
|
|
|
+ {
|
|
|
+ printf("start thread failed,errno:%d\n",::GetLastError());
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+// thread function
|
|
|
+unsigned __stdcall sys_log_process_entry(void *param)
|
|
|
+{
|
|
|
+ //printf("thread sys log_process_entry start\n");
|
|
|
+
|
|
|
+ MSG msg;
|
|
|
+ //check for msg quene isExist or not
|
|
|
+ PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ if(GetMessage(&msg,0,0,0)) //get msg from message queue
|
|
|
+ {
|
|
|
+ switch(msg.message)
|
|
|
+ {
|
|
|
+ case SYS_LOG_MSG:
|
|
|
+ char * pInfo = (char *)msg.wParam;
|
|
|
+
|
|
|
+ #ifndef UT_TEST
|
|
|
+ debug_print(0, pInfo);
|
|
|
+ #else
|
|
|
+ delete[] pInfo;
|
|
|
+ #endif
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
int service_task_init()
|
|
|
{
|
|
|
BufferUtility* bufPtr = BufferUtility::getInstance();
|
|
@@ -300,10 +350,36 @@ int service_task_init()
|
|
|
message_process_thread_init();
|
|
|
sql_process_thread_init();
|
|
|
err_log_process_thread_init();
|
|
|
+ sys_log_process_thread_init();
|
|
|
::Sleep(1000);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+int send_sys_log_message(char* pchr)
|
|
|
+{
|
|
|
+ //send thread message
|
|
|
+ unsigned thread_id = rand() % SYS_LOG_PROCESS_THREAD_NUM;
|
|
|
+ if(!PostThreadMessage(nSysLogThreadID[thread_id], SYS_LOG_MSG, (WPARAM)pchr, 0))//post thread msg
|
|
|
+ {
|
|
|
+ printf("post message failed,errno:%d\n",::GetLastError());
|
|
|
+ delete[] pchr;
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int debug_print_syslog(UINT debugLevel, const char* format, ...)
|
|
|
+{
|
|
|
+ char *buffer = new char[LOG_BUF_SIZE];
|
|
|
+ memset(buffer, 0, LOG_BUF_SIZE);
|
|
|
+ va_list args;
|
|
|
+ va_start (args, format);
|
|
|
+ vsnprintf_s(buffer, LOG_BUF_SIZE, LOG_BUF_SIZE-1, format, args);
|
|
|
+ va_end (args);
|
|
|
+
|
|
|
+ send_sys_log_message(buffer);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
|
|
|
|