initialize

This commit is contained in:
崔一鸣
2018-08-12 19:11:04 +08:00
parent 17e2e2050a
commit a76c0d285f
16 changed files with 8627 additions and 0 deletions

22
sample/old/Makefile Normal file
View File

@@ -0,0 +1,22 @@
CC = gcc
TARGET = test_handle_logger
CFLAGS = -g -Wall -fPIC
LIB = -L../../lib/
LIB += -lMESA_handle_logger -lpthread
INCLUDES = -I../../include/
SOURCES = $(wildcard *.c)
OBJECTS = $(SOURCES:.c=.o)
DEPS = $(SOURCES:.c=.d)
.PHONY : clean all install
all : $(TARGET)
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $(LIB) $(OBJECTS)
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
%.d : %.c
$(CC) $< -MM $(INCLUDES) > $@
-include $(DEPS)
clean :
-rm $(TARGET) $(OBJECTS) $(DEPS)

49
sample/old/sample.conf Normal file
View File

@@ -0,0 +1,49 @@
## Do not modify
* GLOBAL:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%M:%s}]: %msg"
FILENAME = "myeasylog.log"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
## Specifies subsecond precision (previously called 'milliseconds width'). Width can be within range (1-6)
## SUBSECOND_PRECISION = 6
## PERFORMANCE_TRACKING = true
## If log file size of corresponding level is >= specified size, log file will be truncated.
## MAX_LOG_FILE_SIZE = 2097152
## Specifies number of log entries to hold until we flush pending log data
## LOG_FLUSH_THRESHOLD = 100
## Do not modify
* FATAL:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/fatal_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
* INFO:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/info_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
* DEBUG:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/debug_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB - Comment starts with two hashes (##)
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs

View File

@@ -0,0 +1,81 @@
#include "../../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);
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_DEBUG, "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/sample_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;
}