|
@@ -1,9 +1,15 @@
|
|
|
// test4log.cpp : 定义控制台应用程序的入口点。
|
|
|
//
|
|
|
|
|
|
+#if defined(_MSC_VER)
|
|
|
#include "stdafx.h"
|
|
|
+#else
|
|
|
+#define WINAPI
|
|
|
+#endif //_MSC_VER
|
|
|
+
|
|
|
#include <assert.h>
|
|
|
#include <time.h>
|
|
|
+#include <thread>
|
|
|
#include "log4vendor.h"
|
|
|
#include <iostream>
|
|
|
|
|
@@ -50,49 +56,61 @@ void logInitize_FileRecord()
|
|
|
{
|
|
|
std::string err_msg;
|
|
|
cmb::log_init_config config;
|
|
|
- config.dev_name =_T("PinPad");
|
|
|
+ config.dev_name =("PinPad");
|
|
|
config.log_type = CMB_LOG_TYPE_FILE;
|
|
|
config.log_level = CMB_LOG_LEVEL_ALL;
|
|
|
- config.log_dir =_T("C:\\rvc\\dbg\\");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
cmb::log4vendor::init(config, err_msg);
|
|
|
assert(err_msg.empty());
|
|
|
|
|
|
- LOG4VTM(TRACE,_T("This is first TRACE type message."));
|
|
|
- LOG4VTM(INFO,_T("This is first INFO type message."));
|
|
|
- LOG4VTM(WARN,_T("This is first WARN type message."));
|
|
|
- LOG4VTM(ERROR,_T("This is first ERROR type message."));
|
|
|
- LOG4VTM(FATAL,_T("This is first FATAL type message."));
|
|
|
+ LOG4VTM(TRACE,("This is first TRACE type message."));
|
|
|
+ LOG4VTM(INFO,("This is first INFO type message."));
|
|
|
+ LOG4VTM(WARN,("This is first WARN type message."));
|
|
|
+ LOG4VTM(ERROR,("This is first ERROR type message."));
|
|
|
+ LOG4VTM(FATAL,("This is first FATAL type message."));
|
|
|
}
|
|
|
|
|
|
void logInitize_Console()
|
|
|
{
|
|
|
std::string err_msg;
|
|
|
cmb::log_init_config config;
|
|
|
- config.dev_name =_T("PinPad");
|
|
|
+ config.dev_name =("PinPad");
|
|
|
config.log_type = CMB_LOG_TYPE_FILE | CMB_LOG_TYPE_CONSOLE;
|
|
|
config.log_level = CMB_LOG_LEVEL_ALL;
|
|
|
- config.log_dir =_T("C:\\rvc\\dbg\\");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
cmb::log4vendor::init(config, err_msg);
|
|
|
std::cout << err_msg << std::endl;
|
|
|
assert(err_msg.empty());
|
|
|
|
|
|
- LOG4VTM(TRACE,_T("This is first TRACE type message."));
|
|
|
- LOG4VTM(INFO,_T("This is first INFO type message."));
|
|
|
- LOG4VTM(WARN,_T("This is first WARN type message."));
|
|
|
- LOG4VTM(ERROR,_T("This is first ERROR type message."));
|
|
|
- LOG4VTM(FATAL,_T("This is first FATAL type message."));
|
|
|
+ LOG4VTM(TRACE,("This is first TRACE type message."));
|
|
|
+ LOG4VTM(INFO,("This is first INFO type message."));
|
|
|
+ LOG4VTM(WARN,("This is first WARN type message."));
|
|
|
+ LOG4VTM(ERROR,("This is first ERROR type message."));
|
|
|
+ LOG4VTM(FATAL,("This is first FATAL type message."));
|
|
|
}
|
|
|
|
|
|
void logInitize_SupportDirPathWithoutSlash()
|
|
|
{
|
|
|
std::string err_msg;
|
|
|
cmb::log_init_config config;
|
|
|
- config.dev_name =_T("PinPad");
|
|
|
+ config.dev_name =("PinPad");
|
|
|
config.log_type = CMB_LOG_TYPE_FILE;
|
|
|
config.log_level = CMB_LOG_LEVEL_ALL;
|
|
|
- config.log_dir =_T("C:\\rvc\\dbg");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
cmb::log4vendor::init(config, err_msg);
|
|
|
assert(err_msg.empty());
|
|
@@ -102,22 +120,30 @@ void logInitize_SupportDiffLogLevel_ERROR()
|
|
|
{
|
|
|
std::string err_msg;
|
|
|
cmb::log_init_config config;
|
|
|
- config.dev_name =_T("PinPad");
|
|
|
+ config.dev_name =("PinPad");
|
|
|
config.log_type = CMB_LOG_TYPE_FILE;
|
|
|
config.log_level = CMB_LOG_LEVEL_ERROR;
|
|
|
- config.log_dir =_T("C:\\rvc\\dbg\\");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
cmb::log4vendor::init(config, err_msg);
|
|
|
assert(err_msg.empty());
|
|
|
|
|
|
- LOG4VTM(TRACE,_T("The TRACE type message would not record!"));
|
|
|
- LOG4VTM(INFO,_T("The INFO type message would not record!"));
|
|
|
- LOG4VTM(WARN,_T("The WARN type message would not record!"));
|
|
|
- LOG4VTM(ERROR,_T("This is first ERROR type message."));
|
|
|
- LOG4VTM(FATAL,_T("This is first FATAL type message."));
|
|
|
+ LOG4VTM(TRACE,("The TRACE type message would not record!"));
|
|
|
+ LOG4VTM(INFO,("The INFO type message would not record!"));
|
|
|
+ LOG4VTM(WARN,("The WARN type message would not record!"));
|
|
|
+ LOG4VTM(ERROR,("This is first ERROR type message."));
|
|
|
+ LOG4VTM(FATAL,("This is first FATAL type message."));
|
|
|
}
|
|
|
|
|
|
+#if defined(_MSC_VER)
|
|
|
#include <process.h>
|
|
|
+#else
|
|
|
+#include <pthread.h>
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
#define random(x) (rand()%x)
|
|
|
int get_random(int reft, int right)
|
|
@@ -129,11 +155,13 @@ int get_random(int reft, int right)
|
|
|
return c;
|
|
|
}
|
|
|
|
|
|
-UINT WINAPI thread1(LPVOID param)
|
|
|
+void thread1(int param)
|
|
|
{
|
|
|
- int i = (int)param;
|
|
|
- TRACE4VTM_FUNCTION(&i);
|
|
|
- LOG4VTM(INFO,_T("current thread: ") << GetCurrentThreadId());
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ LOG4VTM(INFO, ("current thread: ") << GetCurrentThreadId());
|
|
|
+#else
|
|
|
+ LOG4VTM(INFO, ("current thread: ") << (int)pthread_self());
|
|
|
+#endif //_MSC_VER
|
|
|
const int times = 3000;
|
|
|
int count = 0;
|
|
|
do
|
|
@@ -141,90 +169,109 @@ UINT WINAPI thread1(LPVOID param)
|
|
|
const int nInterval = get_random(0, 3000);
|
|
|
const int nLevel = nInterval % 6;
|
|
|
if(nLevel == 0) {
|
|
|
- LOG4VTM(ERROR,_T("this is a ERROR log, times: ") << count);
|
|
|
+ LOG4VTM(ERROR,("this is a ERROR log, times: ") << count);
|
|
|
} else if(nLevel == 1) {
|
|
|
- LOG4VTM(FATAL, _T("this is a FATAL log, times: ") << count);
|
|
|
+ LOG4VTM(FATAL, ("this is a FATAL log, times: ") << count);
|
|
|
} else if(nLevel == 2) {
|
|
|
- LOG4VTM(INFO,_T("this is a INFO log, times: ") << count);
|
|
|
+ LOG4VTM(INFO,("this is a INFO log, times: ") << count);
|
|
|
} else if(nLevel == 3) {
|
|
|
- LOG4VTM(DEBUG,_T("this is a DEBUG log, times: ") << count);
|
|
|
+ LOG4VTM(DEBUG,("this is a DEBUG log, times: ") << count);
|
|
|
} else if(nLevel == 4) {
|
|
|
- LOG4VTM(WARN,_T("this is a WRAN log, times: ") << count);
|
|
|
+ LOG4VTM(WARN,("this is a WRAN log, times: ") << count);
|
|
|
} else if(nLevel == 5) {
|
|
|
- LOG4VTM(TRACE,_T("this is a TRACE log, times: ") << count);
|
|
|
+ LOG4VTM(TRACE,("this is a TRACE log, times: ") << count);
|
|
|
}
|
|
|
//Sleep(nInterval);
|
|
|
} while (++count < times);
|
|
|
-
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
void MultiThreadTest()
|
|
|
{
|
|
|
- srand((int)time(0));
|
|
|
- int count = 30;
|
|
|
- HANDLE handle[30];
|
|
|
- for(int i=0; i<30; ++i)
|
|
|
- handle[i] = (HANDLE)_beginthreadex(NULL, 0,thread1, (LPVOID)i, 0, NULL);
|
|
|
-
|
|
|
- WaitForMultipleObjects(30, handle, TRUE, INFINITE);
|
|
|
+ srand((int)time(0));
|
|
|
+ int count = 30;
|
|
|
+ std::thread* handle[30];
|
|
|
+ for (int i = 0; i < 30; ++i)
|
|
|
+ handle[i] = new std::thread(thread1, i);
|
|
|
+
|
|
|
+ for (int i = 0; i < 30; ++i) {
|
|
|
+ if (handle[i]->joinable())
|
|
|
+ handle[i]->join();
|
|
|
+ delete handle[i];
|
|
|
+ handle[i] = nullptr;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void logInitize_SupportDiffLogLevel_OFF()
|
|
|
{
|
|
|
std::string err_msg;
|
|
|
cmb::log_init_config config;
|
|
|
- config.dev_name =_T("PinPad");
|
|
|
+ config.dev_name =("PinPad");
|
|
|
config.log_type = CMB_LOG_TYPE_FILE;
|
|
|
config.log_level = CMB_LOG_LEVEL_OFF;
|
|
|
- config.log_dir =_T("C:\\rvc\\dbg\\");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
cmb::log4vendor::init(config, err_msg);
|
|
|
assert(err_msg.empty());
|
|
|
|
|
|
- LOG4VTM(TRACE,_T("The TRACE type message would not record!"));
|
|
|
- LOG4VTM(INFO,_T("The INFO type message would not record!"));
|
|
|
- LOG4VTM(WARN,_T("The WARN type message would not record!"));
|
|
|
- LOG4VTM(ERROR,_T("The ERROR type message would not record!"));
|
|
|
- LOG4VTM(FATAL,_T("The FATAL type message would not record!"));
|
|
|
+ LOG4VTM(TRACE,("The TRACE type message would not record!"));
|
|
|
+ LOG4VTM(INFO,("The INFO type message would not record!"));
|
|
|
+ LOG4VTM(WARN,("The WARN type message would not record!"));
|
|
|
+ LOG4VTM(ERROR,("The ERROR type message would not record!"));
|
|
|
+ LOG4VTM(FATAL,("The FATAL type message would not record!"));
|
|
|
}
|
|
|
|
|
|
+#if defined(_MSC_VER)
|
|
|
int _tmain(int argc, _TCHAR* argv[])
|
|
|
+#else
|
|
|
+int main(int argc, char* argv[])
|
|
|
+#endif //_MSC_VER
|
|
|
{
|
|
|
std::string err_msg;
|
|
|
assert(cmb::log4vendor::instance() != NULL);
|
|
|
{
|
|
|
cmb::log_init_config config1;
|
|
|
- config1.dev_name =_T("");
|
|
|
+ config1.dev_name =("");
|
|
|
config1.log_type = CMB_LOG_TYPE_FILE;
|
|
|
- config1.log_dir = _T("C:\\rvc\\dbg\\");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config1.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config1.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
|
|
|
cmb::log4vendor::init(config1, err_msg);
|
|
|
- LOG4VTM(INFO,_T("This message would not be record with illegal dev name!"));
|
|
|
- assert(!err_msg.empty() &&_T(""));
|
|
|
+ LOG4VTM(INFO,("This message would not be record with illegal dev name!"));
|
|
|
+ assert(!err_msg.empty() &&(""));
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
cmb::log_init_config config2;
|
|
|
- config2.dev_name =_T("PinPad");
|
|
|
+ config2.dev_name =("PinPad");
|
|
|
config2.log_type = ~(CMB_LOG_TYPE_CONSOLE | CMB_LOG_TYPE_FILE | CMB_LOG_TYPE_SOCKET);
|
|
|
- config2.log_dir =_T("C:\\rvc\\dbg\\");
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ config2.log_dir = ("C:\\rvc\\dbg\\");
|
|
|
+#else
|
|
|
+ config2.log_dir = ("/opt/rvc/dbg/");
|
|
|
+#endif //_MSC_VER
|
|
|
cmb::log4vendor::init(config2, err_msg);
|
|
|
- LOG4VTM(INFO,_T("This message would not be record with illegal log type!"));
|
|
|
- assert(!err_msg.empty() &&_T(""));
|
|
|
+ LOG4VTM(INFO,("This message would not be record with illegal log type!"));
|
|
|
+ assert(!err_msg.empty() &&(""));
|
|
|
}
|
|
|
|
|
|
|
|
|
{
|
|
|
cmb::log_init_config config;
|
|
|
- config.dev_name =_T("PinPad");
|
|
|
+ config.dev_name =("PinPad");
|
|
|
config.log_type = CMB_LOG_TYPE_FILE;
|
|
|
- config.log_dir =_T("");
|
|
|
+ config.log_dir =("");
|
|
|
|
|
|
cmb::log4vendor::init(config, err_msg);
|
|
|
- LOG4VTM(INFO,_T("This message would not be record with illegal dir path !"));
|
|
|
- assert(!err_msg.empty() &&_T(""));
|
|
|
+ LOG4VTM(INFO,("This message would not be record with illegal dir path !"));
|
|
|
+ assert(!err_msg.empty() &&(""));
|
|
|
|
|
|
}
|
|
|
|
|
@@ -251,5 +298,4 @@ int _tmain(int argc, _TCHAR* argv[])
|
|
|
MultiThreadTest();
|
|
|
|
|
|
return 0;
|
|
|
-}
|
|
|
-
|
|
|
+}
|