同步内网版本
This commit is contained in:
80
demo/test_handle_logger.c
Normal file
80
demo/test_handle_logger.c
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "MESA_handle_logger.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void *sample_handle = NULL;
|
||||
void *test_handle = NULL;
|
||||
|
||||
#define LOG_NUM 100
|
||||
#define THREAD_NUM 100
|
||||
|
||||
void call_logger(int log_num, int thread_num)
|
||||
{
|
||||
int i = 0;
|
||||
for(i = 0; i < log_num; i++)
|
||||
{
|
||||
MESA_handle_runtime_log(sample_handle, RLOG_LV_INFO, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
//sleep(1);
|
||||
MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
//sleep(1);
|
||||
MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void *thread_logger(void *arg)
|
||||
{
|
||||
int thread_num = (int)(unsigned long long)arg;
|
||||
printf("thread %d created! \n", thread_num);
|
||||
call_logger(LOG_NUM, thread_num);
|
||||
printf("thread %d finished! \n", thread_num);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
printf("ctrl+c recviced!\n");
|
||||
MESA_destroy_runtime_log_handle(sample_handle);
|
||||
MESA_destroy_runtime_log_handle(test_handle);
|
||||
sample_handle = NULL;
|
||||
test_handle = NULL;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t t[THREAD_NUM];
|
||||
int i = 0;
|
||||
|
||||
sample_handle = MESA_create_runtime_log_handle("./log/", RLOG_LV_DEBUG);
|
||||
if(sample_handle == NULL)
|
||||
{
|
||||
printf("get log sample_handle error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
test_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG);
|
||||
if(test_handle == NULL)
|
||||
{
|
||||
printf("get log test_handle error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < THREAD_NUM; i++)
|
||||
{
|
||||
pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i));
|
||||
}
|
||||
signal(SIGINT, sig_handler);
|
||||
while(1)
|
||||
;
|
||||
//MESA_destroy_runtime_log_handle(sample_handle);
|
||||
//MESA_destroy_runtime_log_handle(test_handle);
|
||||
//sample_handle = NULL;
|
||||
//test_handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user